There is an example about the pointer to a member function.
#include <stdlib.h>
#include <iostream>
using namespace std;
class B {
public:
virtual void set(int val) {
val_ = val;
cout<<"B : "<<val_<<endl;
}
protected:
int val_;
};
class D : public B {
public:
virtual void set(int val) {
val_ = val;
cout<<"D : "<<val_<<endl;
}
};
int main() {
B b;
D d;
B *pb = &d;
void (B::*fn) (int) = &B::set;
(pb->*fn)(12);
//void (D::*fx)(int) = &B::bset;
//(d.*fx)(11);
return 0;
};
June 18th Tuesday (六月 十八日 木曜日)
最新推荐文章于 2021-12-22 12:48:17 发布