Initialization (programming): Difference between revisions

Content deleted Content added
No edit summary
Danielx (talk | contribs)
m Initializer list: example was not well formatted
Line 31:
A [[constructor]] of a class/struct can have an '''initializer list''' within the definition but prior to the constructor body. It assigns initial values to the members of the class/struct object.
Example:
 
:struct int_complex {int re, im; complex() : re(0), im(0) { }};
struct int_complex {
int re, im;
:struct int_complex {int re, im; complex() : re(0), im(0) { }};
};
 
Here, the construct " : re(0), im(0)" is the initializer list.