Here's one way to find out without reading through endless standardese (insert something about fishing and teaching).
You need to print something during the member initialization.
You can do that if your member is also an instance of a class:
struct Member
{
Member(int i) { cout << "Member initialized" << endl; }
};
struct A
{
A() { cout << "A initialized" << endl; }
};
struct B : A
{
B() : member(0) { cout << "B initialized" << endl; }
Member member;
};
int main()
{
B b;
}
This prints
A initialized
Member initialized
B initialized
As an aside, this is one situation where it's possible to employ the "comma operator", which lets us avoid that extra class.
Writing B
like this:
struct B : A
{
B() : member((cout << "Member initialized\n", 0)) { cout << "B initialized" << endl; }
int member;
};
produces the same output.
The comma operator evaluates its left hand side, throws away the result, and returns the right hand side. (It needs an extra pair of parentheses here in order to not be interpreted as two parameters.)
It can be useful when you need to trace evaluation but there's no obvious way to insert tracing.