< Previous | Contents | Next >

Using Constructors

When you instantiate objects, you often want to do some initializationusually assigning values to data members. Luckily, a class has a special member function known as a constructor that is automatically called every time a new object is instantiated. This is a big convenience because you can use a constructor to perform an initialization of the new object.

Using Constructors 261


 

Introducing the Constructor Critter ProgramDeclaring and Defining a ConstructorCalling a Constructor Automatically