Note that there are some explanatory texts on larger screens.

plurals
  1. POInheritance issues with template classes
    primarykey
    data
    text
    <p>Can anyone figure out a nice way to get the following code to work? (This is, once again, an incredibly simplified way of doing this)</p> <p><pre><code></p> <p>template &lt;class f, class g> class Ptr;</p> <p>class RealBase { };</p> <p>template &lt;class a, class b, class c = Ptr&lt;a,b> > class Base : public RealBase { public: Base(){}; };</p> <p>template &lt;class d, class e> class Derived : public Base &lt;d,e> { public: Derived(){}; void DerivedMethod(){}; }; template &lt;class f, class g> class Ptr { public: Ptr(){}; Ptr(Base&lt;f,g,Ptr&lt;f,g> >* a){in = a;}; Base&lt;f,g,Ptr&lt;f,g> >* operator->() { return in; }; private: Base&lt;f,g,Ptr&lt;f,g> >* in; };</p> <p>typedef Derived&lt;double,double> DDerived;</p> <p>int main() { Base&lt;int,int> b = Base&lt;int,int>(); Derived&lt;double,double> d = Derived&lt;double,double>(); DDerived dd = DDerived(); Ptr&lt;double,double> p(&amp;dd); p->DerivedMethod(); return 1; } </pre></code></p> <p>At the moment the compiler moans because a Base&lt;> doesn't have a DerivedMethod();</p> <p>EDIT</p> <p>I do understand the problem here, my bad for a lack of explanation in the first case (I was in a rush). [This is very cut down code by the way so, yes, for the sake of simplicity I don't have destructors or methods that actually DO anything. Just ignore that, it makes no difference to the problem.]</p> <p>What I need to happen is that an iterator (that isn't detailed here) that deals only with the derived class (D_Derived) need to access a method that is contained within a derived class and not the base class. Simply plonking this method into the base class isn't really an option because this error is going to occur a LOT if I have to do that. (There are about 10 classes built on the real base class, and they all have derived methods of their own. Like 20 of them. Each.)</p> <p>Can anyone think of another way to achieve this functionality?</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. 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