Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>I don't know in advance I am going to have a Blah, only a Blah.</p> </blockquote> <p>From the language point of view, <code>Blah&lt;T&gt;</code> is meaningless because <code>T</code> doesn't exist. Depending on what you're exactly trying to do, you can</p> <p>make <code>Foo</code> a template, too, so that you can declare a template parameter <code>T</code>:</p> <pre><code>template&lt;typename T&gt; class Foo { public: Foo getInstance(const string&amp; fooType); ... private: shared_ptr&lt; FooImpl&lt;T&gt; &gt; m_impl; }; </code></pre> <p>which 'fixes' the choice of <code>T</code> when you declare a variable of type <code>Foo&lt;T&gt;</code>;</p> <p>or make <code>FooImpl</code> explicitly derive from a common base:</p> <pre><code>class FooBase { // need to define the interface here }; // this is a class definition whereas previously you only needed a declaration template&lt;typename T&gt; class FooImpl: public FooBase { // definition here }; class Foo { public: Foo getInstance(const string&amp; fooType); // we needed the definition of FooImpl for this member // in addition this member is quite obviously a template template&lt;typename T&gt; void set(FooImpl&lt;T&gt; const&amp; foo) { m_impl.reset(new FooImpl&lt;T&gt;(foo)); } // not a member template! void use() { // any use of m_impl will be through the FooBase interface } private: shared_ptr&lt;FooBase&gt; m_impl; }; </code></pre> <p>where for a given <code>Foo</code> instance any kind of <code>FooImpl&lt;T&gt;</code> can be set dynamically and then used through the <code>FooBase</code> interface. This is a kind of <a href="https://stackoverflow.com/questions/5450159/type-erasure-techniques">type erasure</a> as it's called in the C++ world.</p>
    singulars
    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.
    2. 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