Is it possible to implement an abstract base class with members inherited from another parent class in C++?
It works in C#, so I tried doing it in C++:
// Virtual destructors omitted for brevity
class ITalk
{
public:
virtual void SayHi() = 0;
};
class Parent
{
public:
void SayHi();
};
class Child : public Parent, public ITalk
{
};
void Parent::SayHi()
{
std::printf("Hi
");
}
My compiler didn't really like it though:
ITalk* lChild = new Child(); // You idiot, Child is an abstract class!
lChild->SayHi();
I can't add public ITalk
to the Parent
class because "base-class 'ITalk' is already a base-class of 'Parent'." I could move public ITalk
up to the Parent
class, but in my particular scenario that complicates a lot of things.