- Creating the object
- Without initialization list: Assign default values to the object's member variables
- With initialization list: Assign specified values in initialization list to member variables
- Running the constructor's body
Warning: there is no guarantee on the order of assignments (see example).
Before:
MyClass::MyClass()
{
member1 = 1;
member2 = 2;
member3 = member2;
}
After:
MyClass::MyClass()
: member1(1),
member2(2)
//, member3(member2) // No guarantee member2
// was set before here
{
member3 = member2; // need to assign here
}
No comments:
Post a Comment