C++language, you can describe a pointer to a data member of a class and a pointer to a member function of a class. Both of these pointers must be used in conjunction with the object or pointer to the object. 1A pointer to a data member of a class is defined in the format: type name Class Name::*pointer; This description does not say that the pointer belongs to a class, but rather that the pointer can only point to a member of the specified type of the specified class. 2pointer to a class's member function type name (class name::*pointer) (parameter table); Similarly, a function pointer does not belong to a class, but to a function that can only point to a specified prototype of a class. #include<iostream.h>classa{ Public: intA; intb; A () {}intf () {intA::* p=&a::a; This->*p= -;//You must use the this pointer return 0; } };voidMain () {int(A:: *q) (); A Obja; intA::* p=&a::b; Obja.*p=Ten; cout<<obja.b<<Endl; Q=A::f; (Obja.*Q) ();//note the preceding parenthesescout<<obja.a<<Endl;}
Pointers to class members