4.2. Classes

C++ user-defined data types combine private members (state variables and private member functions) with public members (data members and member functions). The statement

struct Struct_name { 
private:
   . . . members . . .                  // Inside view
public:
   . . . members . . .                  // Outside view
};

defines the inside and outside views of a new data type called Struct_name. Although we have been working only with structures up to now, the following class definition is equivalent.

					class Class_name { 
   . . . members . . .                  // Inside view
public:
   . . . members . . .                  // Outside view
};

C++ classes are structures whose default access specification is private, making the private keyword optional. A class, therefore, is nothing more than a structure with ...

Get Navigating C++ and Object-Oriented Design 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.