#define DECLARE_NEWMSG(ClassName,ClassID)
static ClassName* FromMsg(ClassA* psg)
{
return dynamic_cast<ClassName*>(psg);
}
static ClassA* newMsg()
{
return new ClassName;
}
enum {ID = ClassID};
GET_EVENT = 0x41,
typedef ClassA* (*pNewMsg)(void); //function pointer
typedef struct
{
int Id;
CString Ascii;
pNewMsg MessageFunc; //calls new for the particular message
} stStruct;
ClassA
{
//stmts;
};
ClassA::ClassA(int Id,pNewMsg newMsg,const char* Ascii,void* Data,size_t DataSize)
{
initialises all the variables;
}
class GetEvent : public ClassA
{
public:
DECLARE_NEWMSG(GetEvent,GET_EVENT);
GetEvent();
};
static const GetEvent cGetEvent;
GetEvent::GetEvent():ClassA(ID, newMsg, NULL, NULL, 0)
{
//no stmts inside;
}
无法理解GetEvent :: GetEvent():ClassA(ID,NewMsg,NULL,NULL,0)行。它们是否将派生值然后将其分配到基类的构造函数中。如果newMsg在调用基类构造函数时被定义为未定义,那么newMsg将保留为未定义状态。 如果采用相反的情况,则ID将保留为未定义状态。 。在C++中调用的基类和派生类构造函数
莫非不能够理解语句的执行,
static const GetEvent cGetEvent;
GetEvent::GetEvent():ClassA(ID, newMsg, NULL, NULL, 0)
{
//no stmts inside;
}
并且还函数指针,
typedef ClassA* (*pNewMsg)(void);
#define DECLARE_NEWMSG(ClassName,ClassID)
static ClassName* FromMsg(ClassA* psg)
{
return dynamic_cast<ClassName*>(psg);
}
static ClassA* newMsg()
{
return new ClassName;
}