Member Dereferencing Operators

Before discussing the member dereferencing operators, I must provide a bit of background. C++ lets you define pointers to members of a class, but the process is not simple. To see what's involved, let's look at a sample class that raises some problems:

class example
{
private:
    int feet;
    int inches;
public:
    example();
    example(int ft);
    ~example();
    void show_in();    // display inches member
    example operator+(example &ex);
};

Now suppose you want to define a pointer to the inches member of this class. The following attempt fails:

int * pi = &inches;    // not valid C++

It fails because inches is not type int. Because inches is declared in the class, it has class scope. Therefore, the type for inches must also specify ...

Get The Waite Group's C++ Primer Plus, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.