Dot (.) operator and operator operator
#include <iostream>
using namespace std;
class MyClass {
public:
MyClass(int i) {
val=i;
}
int val;
int doubleValue() {
return val+val;
}
};
int main()
{
int MyClass::*data;
int (MyClass::*func)();
MyClass myObject1(1), myObject2(2);
MyClass *p1, *p2;
p1 = &myObject1;
p2 = &myObject2;
cout << (p1->*func)() << " ";
cout << (p2->*func)() << "\n";
cout << p1->*data << " " << p2->*data << "\n";
return 0;
}
Related examples in the same category