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 に答える