S
srp113
Hello,
I have a base class A, and class D derived from A. I declare a
constructor(ctr) for B() but in definition I dont explicitly call
constructor for A. Compiler however seems to take care of this and
when I construct an object of D, it calls A's ctr first followed by
D's ctr. I tried to see if same holds true for copy constructors: I
defined copy constructor for A and D, and D's copy ctr didnt include
any calls for calling A's copy ctr. In this case though, what happens
is A's default ctr (NOT copy ctr) is called and then B's copy ctr. Why
this discrepancy? In general if you define a constructor (default/
copy) in derived class is it better to include an explicit call to
corr. base classes constructor?
Thanks,
Sunil
I have a base class A, and class D derived from A. I declare a
constructor(ctr) for B() but in definition I dont explicitly call
constructor for A. Compiler however seems to take care of this and
when I construct an object of D, it calls A's ctr first followed by
D's ctr. I tried to see if same holds true for copy constructors: I
defined copy constructor for A and D, and D's copy ctr didnt include
any calls for calling A's copy ctr. In this case though, what happens
is A's default ctr (NOT copy ctr) is called and then B's copy ctr. Why
this discrepancy? In general if you define a constructor (default/
copy) in derived class is it better to include an explicit call to
corr. base classes constructor?
Thanks,
Sunil