"no match for operator->* in pos ->* op"
"no match for operator->* in pos ->* op"
在编译下面的代码时,我得到以下错误。我很困惑,不知道这里出了什么问题。成员函数指针取消引用错误吗?
错误:#g++ fp.cpp
fp.cpp: In member function âvoid Y::callfptr(void (X::*)(int))â:
fp.cpp:33: error: no match for âoperator->*â in âpos ->* opâ
fp.cpp
#include <iostream>
#include <vector>
using namespace std;
class B {
// some base class
};
class X : public B {
public:
int z;
void a(int a) {
cout << "The value of a is "<< a << endl;
}
void f(int b) {
cout << "The value of b is "<< b << endl;
}
};
class Y : public B {
public:
int b;
vector<X> vy;
void c(void) {
cout << "CLASS Y func c called" << endl;
}
void callfptr( void (X::*op)(int));
};
void Y::callfptr(void (X::*op) (int)) {
vector<X>::iterator pos;
for (pos = vy.begin(); pos != vy.end(); pos++) {
(pos->*op) (10);
}
}
不这样做:
(pos->*op) (10);
这样做:
((*pos).*op)(10);
迭代器不需要提供operator ->*
的重载。如果您真的想使用operator ->*
而不是operator .*
,那么您可以这样做:
((pos.operator ->())->*op)(10)
但这只是更啰嗦。
与您的用例相关的一个区别是操作符->*
可以重载,而operator .*
不能。
->*
是operator ->*
。你可以使用
pos.operator->()->*op
或
(*pos).*op
相关文章:
- EASTL矢量<向量<int>>连续的
- "std::list::splice(std::const_iterator pos, std::list&& other)"是否保证将"其他"留空?
- 将卡诺地图简化器从 SOP 更改为 POS 结果
- QT 事件过滤器 mouseEvent->pos().x() 始终为零,但 mouseEvent->pos().y() 工作正常
- 尝试使用QNetworkAccessManager get()而不是QNetworkAccess Manager pos
- 我可以在 SDL 窗口外跟踪我的鼠标 pos 吗?
- 为什么字符串(常量字符* s,size_t pos,size_t len = npos)有效?
- 为什么 gl_FragCoord.z 与 ((pos.z / pos.w) + 1.0) * 0.5 不同?
- C - 创建矢量&lt; vector&lt; double&gt;&gt;矩阵具有分配而不是inizializ
- 获取使用 Qt c++ 在 Linux 中通过 USB 连接的 ESC/POS 打印机的状态
- C 字符串比较“祝您好运”&gt;“再见”
- “POS”未在此范围内声明
- 为什么将此对向量&lt; map&lt; int,int&gt;&gt;中的地图进行更新.失败
- 在 POS 打印机上打印条形码字体
- 变量'pos'正在使用未初始化
- C :对矢量进行排序&lt; struct&gt;(结构有2个整数)基于结构的整数之一
- C 操作员&gt;&gt;与突变器过载
- 明确的专业化“ CheckIntmap&lt;&gt;”实例化
- 是否需要使用 - &gt;运算符在C 中调用成员函数时
- 什么是模板&lt;&gt;inline bla bla