Jump to content

C++ Language/Variables/InitializeWithoutConstructor

From Wikibooks, open books for an open world

Traditionally, data members were initialized by passing parameters to a custom constructor, which would copy those parameterized values to the data members.

In modern C++, you also have the option of just using the default constructor, and specifying those values as an initialization list. The items from that brace-enclosed list will be given to data members based on the order of members within the class definition.

Additional information about initializing without a constructor (includes interactive examples)