开发者

mem_fun_ref question

Why is this code resulting in a compiler error?

#include <iostream>
#include <algorithm>

using namespace std;

class X
{
    public:
        void Print(int x)
        {
            cout << x << endl;
        }
};

int main()
{
    X x;
    mem_fun_ref<void, X, int>(&X::Print) p;
};

Error main.cpp:18: error: e开发者_JAVA技巧xpected ; before p


mem_fun_ref is a function template, so it does not name a type.

mem_fun_ref<void, X, int>(&X::Print) is a function call that returns a value, so it makes no sense that there is a p following it.

The return value of that function call is a mem_fun1_ref_t<void, X, int>, in case you were looking for that.


Did you intend to write

mem_fun1_ref_t<void, X, int> p(&X::Print);
           ^^^^             ^^^

instead? mem_fun_ref is not a class template, but a function template.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜