"no match for operator->* in pos ->* op"
c++, function, pointers
Solution
Instead of doing this:
(pos->*op) (10);
Do this:
((*pos).*op)(10);
Iterators are not required to provide an overload of `operator ->*`. If you really want to use `operator ->*` instead of `operator .*`, then you could do:
((pos.operator ->())->*op)(10)
But this is just more verbose.
A difference which may be relevant for your use case is that operator `->*` can be overloaded, whereas `operator .*` cannot.
Problem
I am getting the following error while compiling the below code. I am confused and am not able to figure out what is wrong here. Is the member function pointer de-referencing wrong? Error: ``` #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); } } ```