I have a hierarchy:
class ICommand
{
public:
virtual void start() = 0;
};
class IExtendedCommand : public ICommand
{
public:
virtual void doSomethingElse() = 0;
};
class ConcreteCommand : public ICommand
{
public:
virtual void start() {};
}
class ExtendedConcreteCommand : public ConcreteCommand, public IExtendedCommand
{
public:
virtual void doSomethingElse() {};
}
ICommand and IExtendedCommand objects are being created by factory.
For some reason when compiler says that all of ICommand’s methods are pure within ExtendedConcreteCommand…
Any ideas why and how to solve this?
PS: Yes I’m porting my Android app to C++/Qt (which I haven’t used for 3 years).
Anyway I’d like to hear how you would cope with this.
EDIT:
What I’m porting is a remote control application for MPC and VLC.
The idea is to create commands that can be sent to the player through a factory.
Factory returns a pointer to an object that implements ICommand. So by switching factory implementations different commands can be created. ICommand declares all the main methods and signals. IExtendedCommand adds some generic info across players. So what I’d like to do is instantiate IExtendedCommand through a factory, set some properties and then launch it with start() method. Also I’d like to reuse ConcreteCommand’s functionality. That leads to the issue I described.
You don’t have a diamond. You have this:
That means that you have two base classes of type
ICommand, and you need to override both their pure methods. But onlyConcreteCommandoverrides the “bottom” version ofstart, and the other one remains unoverridden.If you want an actual diamond, you need to make the
ICommandbase class virtual by using virtual inheritance:class IExtendedCommand : virtual public ICommand, and likewise forConcreteCommand. Alternatively, you can provide another overrider forstartinExtendedConcreteCommand.