奇怪的 GCC 错误:预期在 ',' 之前有主表达式代币
我仍在尝试从 MSVC 迁移到 GCC,但我似乎找不到以下问题的解决方案:
template < typename A, typename B, typename C, typename D >
class Test
{
public:
Test (B* pObj, C fn, const D& args) : _pObj(pObj), _fn(fn), _args(args)
{
}
A operator() ()
{
return _args.operator() < A, B, C > (_pObj, _fn); // error: expected primary-expression before ',' token
}
B* _pObj;
C _fn;
D _args;
};
请帮忙!
I'm still trying to migrate from MSVC to GCC, but I can't seem to find a solution to the following problem:
template < typename A, typename B, typename C, typename D >
class Test
{
public:
Test (B* pObj, C fn, const D& args) : _pObj(pObj), _fn(fn), _args(args)
{
}
A operator() ()
{
return _args.operator() < A, B, C > (_pObj, _fn); // error: expected primary-expression before ',' token
}
B* _pObj;
C _fn;
D _args;
};
Please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试 return _args.template operator()
A、B、C> (_pObj,_fn);
。如果没有
template
关键字,解析将会有所不同。如果没有额外使用template
,编译器不知道后面的小于标记 (<) 并不是真正的“小于”,而是模板参数列表的开头。14.2/4
PS:阅读此 Stackoverflow 常见问题解答条目
Try
return _args.template operator() < A, B, C > (_pObj, _fn);
.Without the
template
keyword the parse would be different. Without that extra use oftemplate
, the compiler does not know that the less-than token (<) that follows is not really "less than" but the beginning of a template argument list.14.2/4
P.S: Read this Stackoverflow FAQ Entry