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)
template <class f, class g> class Ptr;
class RealBase { };
template <class a, class b, class c = Ptr<a,b> > class Base : public RealBase { public: Base(){}; };
template <class d, class e> class Derived : public Base <d,e> { public: Derived(){}; void DerivedMethod(){}; }; template <class f, class g> class Ptr { public: Ptr(){}; Ptr(Base<f,g,Ptr<f,g> >* a){in = a;}; Base<f,g,Ptr<f,g> >* operator->() { return in; }; private: Base<f,g,Ptr<f,g> >* in; };
typedef Derived<double,double> DDerived;
int main() { Base<int,int> b = Base<int,int>(); Derived<double,double> d = Derived<double,double>(); DDerived dd = DDerived(); Ptr<double,double> p(&dd); p->DerivedMethod(); return 1; }
At the moment the compiler moans because a Base<> doesn't have a DerivedMethod();
EDIT
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.]
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.)
Can anyone think of another way to achieve this functionality?
OK. After trying about 10 different methods (
static_cast,reinterpret_castetc.) you can just cast it.Nasty. But it works, and that’s all that counts.
Cheers to everyone who repeated the question back at me.