gpt4 book ai didi

c++ - mem_fun_ref 问题

转载 作者:行者123 更新时间:2023-11-30 02:11:05 25 4
gpt4 key购买 nike

为什么这段代码会导致编译器错误?

#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;
};

错误main.cpp:18: 错误:预期;在 p 之前

最佳答案

mem_fun_ref 是一个函数模板,所以它没有命名类型。

mem_fun_ref<void, X, int>(&X::Print)是一个返回值的函数调用,所以 p 是没有意义的跟着它。

该函数调用的返回值是 mem_fun1_ref_t<void, X, int> ,以防您正在寻找它。

关于c++ - mem_fun_ref 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3914633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com