7.4. Class Scope

Image

Every class defines its own new scope. Outside the class scope, ordinary data and function members may be accessed only through an object, a reference, or a pointer using a member access operator (§ 4.6, p. 150). We access type members from the class using the scope operator . In either case, the name that follows the operator must be a member of the associated class.

Screen::pos ht = 24, wd = 80; // use the pos type defined by ScreenScreen scr(ht, wd, ' ');Screen *p = &scr;char c = scr.get(); // fetches the get member from the object scrc = p->get();       // fetches the get member from the object to which p points

Get C++ Primer, Fifth 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.