I have a singleton class that implements two other abstract classes.
My monkey::getMonkey fails because of thisMonkey = new monkey() returns “object of abstract class type “monkey” is not allowed”. I know you cannot instantiate abstract classes, but my monkey implements two abstract classes (meaning it is not abstract.. right?)
What is a solution to this?
class monkey : public animal,
public npc {
public:
~monkey();
static monkey* getMonkey();
private:
monkey();
static monkey* thisMonkey;
}
monkey::monkey() {};
monkey::~monkey() {};
/* .. implements the virtual methods of animal and npc ... */
monkey::getMonkey() {
if (!thisMonkey)
thisMonkey = new monkey();
return thisMonkey;
}
You don’t show enough to say exactly, but a priori, your class
monkeydoesn’t implement all of the pure virtual functions in the base class. A class which has pure virtual functions which haven’t been overridden is abstract.