If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

To Access Base class Copy Constructor/Assignment Operator

Hi,

How can we able to access Base class Copy Constructor while calling Derived
class Copy Constructor? Or How can we access Base Class Assignment Operator
while calling Derived Class Assignment Operator? Any suggestions?

// It will call only Assignment Operator of Derived Class alone,
// not of Base Class, because of this the Base Class members
// won't be set properly. Hence, to set the parameters properly
// in Base Class, we need to call explicit set() member functions
// of Base Class in the Derived Class Assignment Operator , Abi
// Is there any way to avoid this explicit setting in Derived Class?

d2 = d1;

// It will call only Copy Constructor of Derived Class alone,
// not of Base Class, because of this Base Class members won't
// be set properly. Hence, to set the parameters properly in
// Base Class, we need to call explicit set() member functions
// of Base Class in the Derived Class Copy Constructor, Abi
// Is there any way to avoid this explicit setting in Derived Class?

Yes it seems like a lot of work, but I believe you are missing a subtle point
here.

The whole concept of implementation inheritance is that when you are done
coding and the compiler has done its thing - you have "one" object - with
one public interface. When 'coding' classes we are not packaging functionality
and convenient routines into classes - like we do with procedural programming
- and then just "call" those routines from the base class as we need them.
When you are done coding, the thing you have coded becomes a new "thing",
a new "type of Base". We have enhanced or limited the functionality of whatever
lays below. The rest of the world has no need to even know 'Base' is there.

So yes, if the thing you are super-classing/sub-classing (however you want
to think about it) needs items to get initialized then you will have to gather
them at the highest level - the derived constructor (the public interface)
and take care to make it all transparent to the user of your new type. Users
of your new class are not interested in, or even care if there are "two pieces",
they just want to use this type of thing. If the base class needs special
attention when the new thing is copied - then yes you will have to handle
that inside your new "specialized" creature as well.

Another point to consider is - if you are having all this "extra" over-head
then maybe 'Derived' and 'Base' do not actually have a "kind of" relationship.
Maybe, we are really looking at a "using" relationship or "has a". In which
case just include an object of 'base' in your derived object. (I suspect
that is what we are really looking at here.)