I would like to have an abstract base class with the virtual method getInstance and some classes that inherit from it (all of them are singleton) to implement this method as static. The code would be something along the lines of this:
#include <iostream>
using namespace std;
class Father
{
public:
virtual Father* getInstance();
protected:
static Father* instance;
};
class Son : public Father
{
public:
static Father* getInstance ()
{
if (instance == 0)
instance = new Son();
return instance;
}
private:
Son();
};
int main ()
{
Father* son = Son::getInstance();
}
But the compiler won't let me override the getInstance method as static. Is there any other way to do this?