Original Post
I'm having difficulties with templates. Here's a little piece of code to illustrate my problem: Just to keep things simple i have created this small class
template<class T>
class Ptr
{
public:
T *GetPointer() { return m_Ptr; }
private:
T *m_Ptr;
};
Now i want to create a base class which looks like this:
class Base : public Ptr<Base>
{
public:
void Start()
{
Foo();
}
virtual void Foo();
};
As you can see, the base class derives from the Ptr class. The pointer becomes a pointer to class Base. Now later on, i want to extend the base class:
class Specialized : public Base
{
public:
void Foo();
};
Now it's time to create an instance of the derived class
Specialized S;
S.GetPointer()->Start();
Now the problem: I call the GetPointer method, which returns a pointer to a Base class, and NOT to the derived class. Which means that only Foo() in Base gets called and NOT Foo() in Derived, which i would like. How can i make it so, that the pointer changes from the Base class to the newly created derived class? I've already tryed to do it in a constructor, but that didn't work.
Derived():
Base<Derived>()
{
}
Is this even possible?