#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;
}