The code you posted is wrong.
First, to call B's constructor like that, A has to be derived from B.
Second, you provide 2 implementations for A::A.
I'll explain on the following example:
class B { int _x; public: B(); B(int x); } B::B() { _x = 42; } B::B(int x) { _x = x; } class A : public B { public: A(int x); }; A::A(int x) : B(x) {}
Now, since A is-a B (that's what inheritance is), whenever you construct an A, a base object - B- will also be constructed. If you don't specify it in the initializer list, the default constructor for B - B::B() will be called. Even though you don't declare on, it does exist.
If you specify a different version of the constructor - like in this case, B::B(int), that version will be called.
It's just the way the language is designed.
EDIT:
I edited the code a bit.
Assume the following definition of A's constructor:
A::A(int x) : B(x) {} //... A a(10); //a._x will be 10
If however your constructor is defined as:
A::A(int x) {}
B's default constructor will be called:
A a(10); //a._x will be 42
Hope that's clear.
class B : public A {instead ofclass B {? (Or vice versa with the classes in the other order? Or something like that.){}to initialize aggregates (and more in C++11)"