I've looked at a very similar question, but I'm not quite sure I understand the answer. If I delegate a constructor, which initializations from initialization lists occur?
Example:
MyClass::MyClass(int a, int b)
:
MyClass(a, b, NULL),
int1(a),
int2(b),
pOtherClass(NULL)
{
}
MyClass::MyClass(int a, int b, Other *p)
:
int1(a),
int2(b),
pOtherClass(p)
{
if (pOtherClass == NULL)
{
pOtherClass = &DefaultInstance;
}
}
Here I have to have full initializer lists for both classes due to compiler settings. But what I don't want is:
- First constructor(
int, int
) calls the second constructor(int, int, Other *
) - Second constructor assigns a default address to
pOtherClass
- First constructor's init list assigns
pOtherClass
toNULL
.
The question I linked at the top seems to indicate that this behavior wont occur, but then what is the point of the initializer list in the (int, int
) constructor? Just to keep the compiler happy?