Some background: I have a class, A, with members, B and C and D; I also have an array of A objects; I want to be able to have a function which takes said array and performs a certain calculation on either the B, C, or D members of each of the A objects, depending upon certain circumstances; I want to perform the same calculation regardless of which member is to be used in said calculation, such as always assigning the value 3 or multiplying the member's value by a cofactor of some sort.
My question, therefore, is: Would Anyone be kind enough to point Me in the direction of how I might do this using only one function be it a template or not?
There are pointers to data members, and pointers to member functions:
1 2
MemberType ClassName::*pointerName; //pointer to data member
ReturnType (ClassName::*pointerName)(ParameterTypes...); //pointer to member function
In either case, to obtain the specific pointer you want, you write &ClassName::MemberName.
There are operators .* for direct access via pointer to member, and ->* for indirect access via pointer to member. For data members, it is simply instance.*pointerName or pInstance->*pointerName, and for functions, it is (instance.*pointerName)(args...); or (pInstance->*pointerName)(args...);pointerName can also be a parenthesized expression for dynamically selecting which pointer-to-member to use.