Я пытаюсь создать CnD_Message_Handler родительского типа i_MessageHandler. Конструктор i_MessageHandler принимает i_MessageFactory, другой абстрактный класс. CnD_Message_Factory наследуется от i_MessageFactory. Когда я пытаюсь создать экземпляр CnD_Message_Handler, я получаю следующую ошибку:
ошибка C2664: «CnD_Message_Handler :: CnD_Message_Handler»: невозможно преобразовать параметр 1 из «CnD_Message_Factory» в «const CnD_Message_Handler &»
Причина: невозможно преобразовать из 'CnD_Message_Factory' в 'const CnD_Message_Handler'
Из примеров в Интернете я полагаю, что правильно передаю msg_factory. Я также сбит с толку, поскольку конструктор запрашивает i_MessageFactory (CnD_Message_Factory) вместо i_MessageHandler (CnD_Message_Handler)
Спасибо за любую помощь заранее!
CnD_Device (который создает экземпляры CnD_Message_Factory и CnD_Message_Handler)
CnD_Device::CnD_Device(void)
{
CnD_Message_Factory msg_factory; //Inherited by i_MessageFactory
CnD_Message_Handler msg_handler( msg_factory );
}
CnD_Message_Factory
#include "i_messagefactory.h"
class CnD_Message_Factory :
public i_MessageFactory
{
public:
CnD_Message_Factory(void);
~CnD_Message_Factory(void);
/**
* Creates a message using the stream of data passed in.
* @param id Id of the message to create.
* @param stream Data stream to create the message from.
* @return The created message (which must be returned to the factory by
* calling the deleteMessage() method, or null if the factory could not
* create a message.
*/
Message* createMessage(UInt32 id, const char* stream);
/**
* Returns a message to the factory for deleting/recycling.
* @param msg The message being returned.
*/
void deleteMessage(Message& msg);
};
CnD_Message_Handler
#include "i_messagehandler.h"
class CnD_Message_Handler :
public i_MessageHandler
{
public:
CnD_Message_Handler::~CnD_Message_Handler(void);
/**
* Called by a i_MessageDriver object to process a message received.
* @param msg Message to process.
*/
void CnD_Message_Handler::handleMessage (Message& msg);
/**
* Called by a i_MessageDriver object when an error occurs with an
* interface The exact type of errors are driver specific.
* @param error The error that occurred.
*/
void CnD_Message_Handler::handleError (MessageEvent& error);
/**
* Called by the i_MessageDriver object when an event occurs with an
* interface. The exact type of events are driver specific.
* @param event The event that occurred.
*/
void CnD_Message_Handler::handleEvent (MessageEvent& event);
};
i_MessageHandler
class i_MessageFactory
{
public:
/**
* Destructor.
*/
virtual ~i_MessageFactory(void) { }
/**
* Creates a message using the stream of data passed in.
* @param id Id of the message to create.
* @param stream Data stream to create the message from.
* @return The created message (which must be returned to the factory by
* calling the deleteMessage() method, or null if the factory could not
* create a message.
*/
virtual Message* createMessage(UInt32 id, const char* stream) = 0;
/**
* Returns a message to the factory for deleting/recycling.
* @param msg The message being returned.
*/
virtual void deleteMessage(Message& msg) = 0;
protected:
/**
* Constructor.
*/
i_MessageFactory(void) { }
};