Formerly I asked a question and got a fair response. But I am stucked with below macro definitions.
The below definitions generates a Message Map function like it is in MFC Message Map. But the code below does not compile.
Whole statements starting with this->
are problematic ones except the one in MSG_HANDLER this->meth(msg);
dont know why..
Hence what can be done to correct this issue?
I use VS 2008.
#define MSG_UNPACK(var, id, msg) x##id *var = (x##id *)(msg);
#define BEGIN_MSG_MAP \
protected: \
virtual void dispatchToMsgMap(xMessage *msg)\
{ \
if (msg->msg.message == WM_NULL) \
{ \
return; \
}
#define MSG_HANDLER(meth, wm_msg) \
else if (msg->msg.message == wm_msg) \
{ \
this->meth(msg); \
return; \
}
#define END_MSG_MAP(base) \
else if (msg->msg.message == WM_COMMAND) \
{ \
this->dispatchToCmdMap(msg); \
return; \
} \
else if (msg->msg.message == WM_NOTIFY) \
{ \
this->dispatchToNotifyMap(msg); \
return; \
} \
\
base::dispatchToMsgMap(msg); \
};
#define BEGIN_CMD_MAP \
virtual void dispatchToCmdMap(xMessage *msg)\
{ \
MSG_UNPACK(Cmd, WM_COMMAND, msg); \
\
if (Cmd->ItemID == 0) \
{ \
/* not allowed */ \
}
#define CMD_HANDLER(meth, cmd_id) \
else if (Cmd->ItemID == cmd_id) \
{ \
this->meth(Cmd->ItemID); \
}
#define END_CMD_MAP(base) \
else \
{ \
base::dispatchToCmdMap(msg); \
} \
};
Here, for example this->dispatchToCmdMap(msg); \
is 41st line.
1>d:\devel\coding\vs2008\test2\test2\messagemapper.h(41) : error C2059: syntax error : 'this' 1>d:\devel\coding\vs2008\test2\test2\messagemapper.h(41) : error C2017: illegal escape sequence 1>d:\devel\coding\vs2008\test2\test2\messagemapper.h(42) : error C2059: syntax error : 'return'开发者_运维百科 1>d:\devel\coding\vs2008\test2\test2\messagemapper.h(42) : error C2017: illegal escape sequence 1>d:\devel\coding\vs2008\test2\test2\messagemapper.h(43) : error C2059: syntax error : '}' 1>d:\devel\coding\vs2008\test2\test2\messagemapper.h(43) : error C2143: syntax error : missing ';' before '}' 1>d:\devel\coding\vs2008\test2\test2\messagemapper.h(43) : error C2059: syntax error : '}'
The "illegal escape sequence" part tells me that you have traling whitespace after your \
. Therefore the next lines are not part of the macro.
First, check that you haven't got whitespace after the slashes at the the end of the lines.
If that doesn't help then you should look at the pre-processed output to see what is actually being compiled (and post that here if you need to).
Try to remove spaces after "\". This symbol should be the last in the line.
精彩评论