O'Reilly logo

Sams Teach Yourself C++ in 24 Hours, Third Edition by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Private Versus Public

Other keywords are used in the declaration of a class. Two of the most important are public and private.

All member data and functions are private by default. Private members can be accessed only within methods of the class itself. Public members can be accessed through any object of the class. This distinction is important, but can be confusing. To make it a bit clearer, consider an example from earlier in this chapter:

class Cat
{
    unsigned int  itsAge;
    unsigned int  itsWeight;
    Meow();
};

In this declaration, itsAge, itsWeight, and Meow() are all private, because all members of a class are private by default. This means ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required