Expand|Select|Wrap|Line Numbers
- #include<iostream.h>
- class A
- {
- public:
- int x,y;
- A(){cout<<"\n DefaultConst A";}
- A(int i, int j){cout<<"\n Parm const A"; x=i; y=j;}
- };
- class B : virtual public A
- {
- public:
- int a, b;
- B():A(150,170){cout<<"\n DefaultConst B";}
- };
- class C: public B
- {};
- int main()
- {
- A *ptr;
- C *pobc=new C();
- pobc->a=5; pobc->b=2;
- printf("\n %d %d %d %d", pobc->x, pobc->y,pobc->a, pobc->b);
- }
Output
------
DefaultConst A
DefaultConst B
0 0 5 2
Question
---------
1) Why doesn't the parametrized constructor of A is being called and why x and y are being initialized with 150 and 170