【问题标题】:Having problem passing member function pointers to templatized member function on gcc在 gcc 上将成员函数指针传递给模板成员函数时出现问题
【发布时间】:2011-05-12 19:44:22
【问题描述】:

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

非常感谢您的帮助!

【问题讨论】:

    标签: c++ templates gcc member-function-pointers


    【解决方案1】:

    您不需要typename。删除它,它应该可以工作。 (我在 gcc 4.3.2 上测试过)。

    【讨论】:

    • 谢谢。我不知道为什么我最初把它放在那里。当然,MSVS 不在乎。
    猜你喜欢
    • 1970-01-01
    • 2018-12-07
    • 1970-01-01
    • 2012-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-29
    相关资源
    最近更新 更多