1

我在将成员函数指针传递给 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。

非常感谢您的帮助!

4

1 回答 1

5

你不需要typename。删除它,它应该可以工作。(我在 gcc 4.3.2 上对其进行了测试)。

于 2011-05-12T19:53:47.617 回答