### Overloaded Class Member Access

An expression containing the class member access -> ( arrow) operator has syntax of the form:

          identifier -> name-expression

and is considered a unary operator. The operator function operator->() must be defined as a nonstatic member function.

The following restrictions apply to class member access operators:

- You cannot declare an overloaded arrow operator that is a nonmember function.
- You cannot overload the class member access . (dot) operator.

Consider the following example of overloading the -> ( arrow) operator:

    class Y
    {
    public:
          void f();
    };
    class X
    {
    public:
          Y* operator->();
    };
    X x;
    x->f();

Here x->f() is interpreted as: ( x.operator->() )-> f() .

x .operator->() must return either a reference to a class object or a class object for which the overloaded operator-> function is defined or a pointer to any class. If the overloaded operator-> function returns a class type, the class type must not be the same as the class declaring the function, and the class type returned must contain its own definition of an overloaded -> operator function.

Arrow Operator