6

CONSTRUCTORS AND DESTRUCTORS

6.1 CONSTRUCTORS

We know that a class is more important than the objects it represents. The reason being that once a class is defined, any number of objects of the class type can be churned out at the run time of the program. We also know that the class is a set of specifications that are used by the compiler for the purpose of construction of objects.

In fact for the creation of an object, the compiler creates a function having the same name as the class itself as shown in Fig. 6.1. It may be noted that the name of the class is myClass and the name of the function created by the compiler is also myClass. This function is called as a constructor function. As the name suggests, the constructor function creates an ...

Get Object-Oriented Programming with C++ 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.