- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
为什么这段代码会导致编译器错误?
#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/
为什么这段代码会导致编译器错误? #include #include using namespace std; class X { public: void Print(i
我无法理解 mem_fun_ref。我必须承认,我通常将仿函数用于此类事情,因为它们可以内联以提高速度和利润。但是,这段代码不会成为瓶颈,所以我想尝试一下。 这是我想做的一个例子。我知道还有其他方法可
我已经完成了将普通方法和仿函数作为参数传递的过程,但我怎么一直坚持传递成员变量。 #include #include #include #include #include using nam
不幸的是,我不能使用 C++11 或 Boost。 我有一些类似下面的代码 struct Cell { Cell(int value) : value(value) {} int va
我正在尝试使用 mem_fun_ref 将对象的成员函数的引用发送到另一个函数,但我得到了error C2064: term does not evaluate to a function takin
我用for_each和mem_fun_ref作为例子,但是编译有一些错误,问题是什么 #include #include #include #include using namespace std;
问题是以下代码片段的编译器错误。 这是一个非常简单的程序,用随机整数填充列表并递增每个元素。我使用 std::for_each 调用仿函数来递增我的集合中的每个成员并全部编译。关注 main() 中的
以下代码将无法编译,因为“错误:没有匹配函数调用‘mem_fun_ref()’”(gcc 版本 4.4.6)。 #include #include #include #include #inc
遵循 this page 的建议,我试图让 shared_ptr 调用 IUnknown::Release()而不是删除: IDirectDrawSurface* dds; ... //Allocat
我的问题很简单:我可以做这样的事情吗? 假设类 foo 包含以下成员函数: foo foo::DoSomething(input_type1 input1, input_type2 input2) {
我是一名优秀的程序员,十分优秀!