Encoding/decoding protocol messages to/from various bits of hardware The basic idea is for users of these classes to create derived polymorphic protocol specific messages. There is no protocol type in the interface, it is all hidden behind the scenes.  But the serialised messages can be retrieved with the getMessage functions.

Does this look a logical approach?  Any suggestions?

//base protocol class - interface only
//ref_type is a smart pointers class - not really so relevant to my question
class BaseMessage : public ref_type
{
public:
    virtual ~BaseMessage() {}
    virtual const char* ProtocolName() const = 0;
    virtual bool Encode() = 0;
    virtual bool Decode() = 0;
    //for binary protocols
    virtual void getMessage(unsigned char*&amp; serialised, size_t&amp; length) {}; 
    //for text/xml protocols
    virtual void getMessage(std::string&amp; serialised) {}
};


A specific protocol might then be implemented like this:

class ABCMessage : public BaseMessage {
public: 
   ABCMessage(ABC* msg) : m_msg(msg), m_data(0), m_length(0) {}
   ABCMessage(unsigned char* data, int length) : m_length(length), m_msg(0) 
   {
      m_data = new unsigned char[length]();
      memcpy(m_data, data, length);
   }
   virtual ~ABCMessage();
   virtual const char* ProtocolName() const;
   virtual bool Encode();
   virtual bool Decode();

   virtual void getMessage(unsigned char*&amp; serialised, size_t&amp; length);

protected:
   ABC* m_msg;
   unsigned char* m_data;
   size_t m_length;
};
OK. I doubt it is irrelevant.

//ref_type is a smart pointers class - not really so relevant to my question


Also smart pointers are very hard to get perfectly correct. The standard ones took years and thousands of people looking at them to get correct. So It is usually preferable to use one of the standard smart pointers rather than a home grown one (especially one that is not being reviewed).

So who owns this pointer?

    virtual const char* ProtocolName() const = 0;


There are no ownership semantics associated with pointers. So After I call this I am not sure who is responsible for deleting it. Use a std::string internally and return a const reference to the string.

Not sure why you would want two methods that look like they do the same thing.

    //for binary protocols
    virtual void getMessage(unsigned char*&amp; serialised, size_t&amp; length) {}; 
    //for text/xml protocols
    virtual void getMessage(std::string&amp; serialised) {}


Both are going to be inefficient as you are copying across multiple buffers (input stream buffer into this buffer which is then returned and read again to build an object). What you really want is a getMessage() method that returns a fully constructed object from the stream.

This calss:

class ABCMessage : public BaseMessage {


Is totally broken as it contains an owned RAW pointer but does not implement the rule of three.