A pointer to member is a pointer that can point to a nonstatic
member of a class. Normally a pointer points to an object, but a pointer to member identifies a member of a class, not an object of that class. static
class members are not part of any object, so no special syntax is needed to point to a static
member. Pointers to static
members are ordinary pointers.
The type of a pointer to member embodies both the type of a class and the type of a member of that class. We initialize such pointers to point to a specific member of a class without identifying an object to which that member belongs. When we use a pointer to member, we supply the object whose member we wish to use.
To explain pointers to members, we’ll use a version of the Screen
class from § 7.3.1 (p. 271):
class Screen {
public:
typedef std::string::size_type pos;
char get_cursor() const { return contents[cursor]; }
char get() const;
char get(pos ht, pos wd) const;
private:
std::string contents;
pos cursor;
pos height, width;
};