How do I setup a class that represents an interface? Is this just an abstract base class?
My answer is basically the same as the others but I think there are two other important things to do:
Declare a virtual destructor in your interface or make a protected non-virtual one to avoid undefined behaviours if someone tries to delete an object of type IDemo
.
Use virtual inheritance to avoid problems whith multiple inheritance. (There is more often multiple inheritance when we use interfaces.)
And like other answers:
Use the interface by creating another class that overrides those virtual methods.
class IDemo
{
public:
virtual void OverrideMe() = 0;
virtual ~IDemo() {}
}
Or
class IDemo
{
public:
virtual void OverrideMe() = 0;
protected:
~IDemo() {}
}
And
class Child : virtual public IDemo
{
public:
virtual void OverrideMe()
{
//do stuff
}
}