OOPortal
RationalDB Database Design
prev prev
Course navigation
    Pointer to class member
Types of operators that can be overloaded
In C++, a pointer to a class member is distinct from a pointer to a class. A pointer to class member has type T::*, where T is the class name.
C++ has two operators that act to dereference a pointer to a class member. The pointer to member operators are:
.* and ->*
Think of x.*ptr_mem as first dereferencing the pointer to obtain a member variable and then accessing the member for the designated x.
Here is an example of the difference between .* and ->*:
class trio {
public:
   int a, b, c;
} x, y, *q = &y;

int trio::*p = &trio::b;

x.*p     //gets x.b
q ->*p   //gets y.b
Remember: ->* can be overloaded, while .* cannot be overloaded.
  Course navigation