6.6 DEFAULT CONSTRUCTOR

Objects are initialized with the help of constructor. When we create an object, at that instance, a constructor is used to initialize it. When we specify which constructor to use, there is no ambiguity. However, what if we do not specify any constructor? Consider the following definitions:

Date * d1 = new Date ; or

Date d2 ;

Now the onus is on the compiler to select the constructor. The constructor, which the compiler selects in such situation, is called the default constructor. The compiler selects the constructor without parameters. Hence, in simple terms, constructor without parameters is termed as “default” constructor.

When we try to construct an object without specifying the constructor, three distinct cases have ...

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