O'Reilly logo

Navigating C++ and Object-Oriented Design by Gail Anderson, Paul Anderson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4.12. Class Member Initialization

If a data member object has a default constructor (one with a void argument list or a signature with all default arguments), the compiler calls its constructor automatically when you create an object. In situations where this is not true or in cases where you need to pass arguments to a constructor, a special syntax called member initialization is available. Suppose, for example, a user program instantiates an Act object with a character string title, a Roman number, and a length (say, the number of ASCII characters in a short play).

Act play("theater", 1, 32056);            // Act object 

Here is the Act class with a member initialization list in its constructor:

 class Act { private: char title[80]; // character array ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required