I have two classes implemented:
class DCCmd :
public DCMessage
class DCReply :
public DCMessage
Both are protocol messages that are sent and received in both directions.
Now in the implementation of the protocol I will need to create a message queue, but if DCMessageit is abstract, it will not allow me to do something like this:
class DCMsgQueue{
private:
vector<DCMessage> queue;
public:
DCMsgQueue(void);
~DCMsgQueue(void);
bool isEmpty();
void add(DCMessage &msg);
bool deleteById(unsigned short seqNum);
bool getById(unsigned short seqNum, DCMessage &msg);
};
The problem is that, as the compiler puts, โDCMessage cannot be createdโ because it has a pure abstract method:
virtual BYTE *getParams()=0;
Removing =0and installing empty curly braces in DCMessage.cppfixes the problem, but it's just a hack.
Another solution is that I have to do two DCMsgQueues: DCCmdQueueand DCReplyQueue, but this is just duplicate code for something trivial. Any ideas? =)