Skip to Main Content
Navigating C++ and Object-Oriented Design
book

Navigating C++ and Object-Oriented Design

by Paul Anderson, Gail Anderson
October 1997
Intermediate to advanced content levelIntermediate to advanced
800 pages
20h 48m
English
Pearson
Content preview from Navigating C++ and Object-Oriented Design

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Boost C++ Application Development Cookbook - Second Edition

Boost C++ Application Development Cookbook - Second Edition

Anton Polukhin Alekseevic

Publisher Resources

ISBN: 0135327482Purchase book