아래 코드를 컴파일하는 동안 다음 오류가 발생합니다. 나는 혼란스럽고 여기서 무엇이 잘못되었는지 알아낼 수 없다. 멤버 함수 포인터의 참조가 잘못 되었습니까?"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);
}
}
큰 감사
이 사용할 수 있습니다 – user1663533user1663533 @를 해결 –