【发布时间】:2010-07-06 12:44:52
【问题描述】:
我有以下定义:
template<typename T1, typename T2>
class Test2
{
public:
static int hello() { return 0; }
};
template<typename T>
class Test1
{
public:
static int hello() { return 0; }
};
#define VERIFY_R(call) { if (call == 0) printf("yea");}
有了这些,我尝试编译以下内容:
VERIFY_R( Test1<int>::hello() );
这编译得很好
VERIFY_R( (Test2<int,int>::hello()) );
这也编译得很好,注意调用周围的括号。
VERIFY_R( Test2<int,int>::hello() );
这个,没有括号会产生一个警告和几个语法错误:
warning C4002: too many actual parameters for macro 'VERIFY_R'
error C2143: syntax error : missing ',' before ')'
error C2059: syntax error : ')'
error C2143: syntax error : missing ';' before '}'
error C2143: syntax error : missing ';' before '}'
error C2143: syntax error : missing ';' before '}'
fatal error C1004: unexpected end-of-file found
这是怎么回事?
VS2008 SP1 会发生这种情况。
【问题讨论】:
-
这可能会发生,因为您在 VERIFY_R 的 () 中放入的任何内容都是按字面意思插入的。尝试将宏中的第二个“调用”更改为“(调用)”。
-
这无济于事,这是一个宏观问题。有趣的是:这就是为什么
BOOST_FOREACH会让新手头疼:)
标签: c++ templates visual-studio-2008 syntax c-preprocessor