Wrox Press C++ Tutorial
Summary
You should now understand the basic ideas behind classes in C++. The key points to keep in mind from this chapter are:
-
A class provides a means of defining your own data types. They can reflect whatever types of objects your particular problem requires.
-
A class can contain data members and function members. The function members of a class always have free access to the data members of the same class.
-
Objects of a class are created and initialized using functions called constructors. These are automatically called when an object declaration is encountered. Constructors may be overloaded to provide different ways of initializing an object.
-
Members of a class can be specified as
public, in which case they are freely accessible by any function in a program. Alternatively, they may be specified as private, in which case they may only be accessed by member functions or friend functions of the class.
-
Members of a class can be defined as
static. Only one instance of each static member of a class exists, which is shared amongst all instances of the class, no matter how many objects of the class are created.
-
Every non-static member of a class contains the pointer
this, which points to the current object for which the function was called.
-
Using references to class objects as arguments to function calls can avoid substantial overheads in passing complex objects to a function.
-
A copy constructor, which is a constructor for an object that is initialized with an existing object of the same class, must have its parameter specified as a
const reference.
© 1998 Wrox Press