Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What your macro does is to declare a specializations of some members of a class. This won't create any object and probably not what you really want anyway. What you'd need is a definition of <code>FactoryHelper&lt;SomeClass&gt;::_helper</code> somewhere. A definition of the static member would look something like this:</p> <pre><code>FactoryHelper&lt;foo&gt; FactoryHelper&lt;foo&gt;::_helper; </code></pre> <p>That said, I don't think the is the the way to go at all: all you really need is to instantiate something which registers a factory function and this can be done much simpler and, especially, without macros.</p> <p>Here is how I would do this:</p> <pre><code>template &lt;typename T&gt; struct factory_helper { std::auto_ptr&lt;base&gt; create_fuction() { return std::auto_ptr&lt;base&gt;(new T()); } factory_helper(std::string const&amp; name) { factory.register_class(name, create_function); } }; </code></pre> <p>This assumes that you want to create objects derived from type <code>base</code> and that your factory uses a mapping to function object returning <code>std::auto_ptr&lt;base&gt;</code> as constructor functions and that it has a <code>register_class()</code> function which takes the name and the constructor function as parameters. Neither of these assumptions is inherent to the apprach, though: this is just to fill in some of the blanks you didn't mention. You would register a factory function for a class <code>foo</code> something like this:</p> <pre><code>static factor_helper&lt;foo&gt; foo_helper("foo"); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload