Say I have the following class hierarchy:
class Base
{
virtual int GetClassID(){ return 0;};
public:
Base() { SomeSingleton.RegisterThisObject(this->GetClassID());
}
class Derived
{
virtual int GetClassID(){ return 1;};
public:
Derived():Base(){};
}
Well, it's all simplified from my real case, but that's the general gist of it.
I want to avoid having to call RegisterThisObject in the constructor of each derived class, so I'm trying to move the call to the constructor of the base class.
Is there any pattern that I can use to acomplish this without using the virtual method in the constructor?
See Question&Answers more detail:os