我有问题将成员函数指针传递给gcc上的模板化成员函数。有谁知道如何修改下面的代码让gcc接受我想要做的事情?
class Foo
{
public:
template <class C, class R>
void Execute(R(typename C::*memFn)())
{
}
};
尝试编译代码时出现以下错误:
test.cpp:40: error: 'memFn' was not declared in this scope
test.cpp:40: error: expected primary-expression before '(' token
test.cpp:40: error: expected identifier before '*' token
test.cpp:40: error: expected '(' before '*' token
test.cpp:40: error: 'memFn' was not declared in this scope
test.cpp:40: error: variable or field 'Execute' declared void
我使用的gcc版本是4.4.2。
非常感谢你的帮助!
答案 0 :(得分:5)
您不需要typename
。删除它,它应该工作。 (我在gcc 4.3.2上测试过它。)