Recently I have dumb as a developer, so I took the plunge, got a C++ book and learning how to do things properly. In my head, I know what I would like to do. I effectively want an Interface
that when inherited, must be overridden (if this is possible?). So far, I have the following:
class ICommand{
public:
// Virtual constructor. Needs to take a name as parameter
//virtual ICommand(char*) =0;
// Virtual destructor, prevents memory leaks by forcing clean up on derived classes?
//virtual ~ICommand() =0;
virtual void CallMe() =0;
virtual void CallMe2() =0;
};
class MyCommand : public ICommand
{
public:
// Is this correct?
MyCommand(char* Name) { /* do stuff */ }
virtual void CallMe() {}
virtual void CallMe2() {}
};
I have purposely left how I think the constructor/destructor's should be implemented in ICommand
. I know if I remove the comments, it will not compile. Please could someone:
- Show me how to declare the constructor/destructor's in
ICommand
and how they are meant to be used inMyCommand
- Have I set things up correctly in
ICommand
so thatMyCommand
must overrideCallMe
andCallMe2
.
I hope I haven't missed something really simple...