I defined a multi-line macro function using line continuation character “\” like the following:
#define SHOWMSG( msg ) \
{ \
std::ostringstream os; \
os << msg; \
throw CMyException( os.str(), __LINE__, __FILE__ ); \
}
But it could not pass compilation. BTW, I’m using VS2008 compiler. Would you please tell what’s wrong with my aforesaid macro function?
The usual method for a multi-statement macro is something like:
Without that, the semicolon following the closing brace can cause syntactic problems, such as:
With your code as it was, this would expand to:
In this case, the semicolon would form a null statement following the block in the
ifstatement, and theelsewouldn’t have anifto match up with.