Hi everyone!
can you please explain me WHY in the C class,the line "B _b1;"
doesnt activate the B deafault CTOR?
and i will be glad to get some advices on those codes, i can not answer them correctly, a lot of mistakes..
when do the derived CTOR is called? and so on.. THANKS !
class A
{
public:
A() {cout<<"(1)"<<endl;}
A(A& a) {cout<<"(2)"<<endl;}
virtualvoid f() {cout<<"(3)"<<endl;}
virtual A g() {h(); cout<<"(4)"<<endl; return *this;}
virtual A& h(){A::f(); cout<<"(5)"<<endl; return *this;}
~A() {cout<<"(6)"<<endl;}
};
class B : public A
{
int _x;
A _a1;
A* _ptr;
public:
B():_x(0),_ptr(0) {cout<<"(7)"<<endl;}
B(int num):_x(num),_ptr(0) {cout<<"(8)"<<endl;}
virtualvoid f() {g();cout<<"(10)"<<endl;}
A g() {cout<<"(11)"<<endl; return A::g();}
B k() {cout<<"(12)"<<endl; return *this;}
~B() {cout<<"(13)"<<endl;}
};
class C : public B, public A
{
B _b1;
public:
C():_b1(0) {cout<<"(14)"<<endl;}
A g() {cout<<"(15)"<<endl; B::k(); return *this;}
virtualvoid k() {cout<<"(16)"<<endl;}
virtual ~C() {cout<<"(17)"<<endl;}
};
That overrides any use of the default constructor. You stated you wanted the int constructor. You can't instantiate an object (_b1) with two different constructors (default and int).