C points to a member's pointer
A class has two basic members: functions members and data members. Similarly, there are two pointers that point to members: pointing to the pointer of the function member and pointer to the data member. It is not commonly used because the class generally does not contain public data members, which is only used when the coordination structure and class (Class) are used when inheriting CLASS.
The pointer to the member is one of the most difficult constructs of the C syntax, but this is also a C most powerful feature. It allows you to call a class of function members without having to know the name of this function. This very agile calling tool. Similarly, you can also check and change this data without knowing its members' name by using a pointer to the data member.
Pointer to point to data
Although the grammar of the pointer to the member will make you a little confused, but you will soon find that it is almost the same as ordinary pointers, but it is ahead of the * number :: Symbol and class name, Example: Define a pointer to the INT type:
INT * PI; Define a data member to the INT type class: int A :: * PMI; // PMI is a INT-type member pointing to class A You can initialize it: Class a {public: int Num; INT X;}; / * Pointer to the genre data is not the same as the initialization and assignment method of the normal pointer, because the normal pointer gives it initialized or assigned a value, such as Int J; int * i = & j; pointing to the pointer to the data member gives an address of a class member currently not existing, and this address is only true to determine when the actual class object is used, as follows: * / int A :: * PMI = & a :: Num; The above code is a declaration of an INT-type NUM member that points to class a and initials it to this NUM member. By adding * you can use it in front of PMI * you can use and Change the value of the NUM member of class A: A A1, A2; INT n = a1. * PMI; // assigns A1.Num to Na1. * PMI = 5; // Assign 5 assignments to A1.NUM A2. * PMI = 6; // Assign 6 assignment to 6a2.num If you define a pointer to class A, then the above operation you must use -> * Operator instead: a * pa = new a; int N = PA-> * PMI; PA -> * PMI = 5;
Pointer to function member
It consists of the data type returned by the function member, and the class name followed by :: symbol, pointer name, and function's parameter list. For an example: a pointer to a function member of class A (this function returns an int type): Class a {public: int func ();}; int (a :: * pmf) (); the above definition is to say PMF is a pointer to the function member of the class A. In fact, this pointer and a pointer to a normal pointing function have no difference, just it contains the name of the class and :: symbol. You can call this function in any * PMF (): PMF = & a :: func; a a; (a. * Pmf) (); // call a.func () If you define one first Pointer to the object, then the above operation is used to use -> * instead: a * pa = & a; (pa-> * pmf) (); // Call PA-> FUNC () pointing to the pointer to the function member to consider polymorphism Sex. So, this call will be dynamically recycled when you call a virtual function member through a pointer. Another place to pay attention to, you can't take a class constructor and the address of the destructor.