R
Russ Ford
Hi all,
I'm trying to get inheritance and constructors clear in my head (and
in my code). I have the following inheritance situation (all
derivations public):
A is the base class
B is inherited from A
C is inherited from B
D is inherited from A
E is inherited from D.
Simple enough. Now here's the deal:
A's data is all basic data types (all doubles, to be precise).
B includes a CArray (which doesn't have a = that I understand).
C includes some more numbers.
D and E only include additional numbers.
The code I'm writing is complaining that there's no = operator defined
for a class D or E assignment. In essence, "memberwise copying" will
be fine for data in all classes except B, where I need to write some
code.
I want to make all assignments work as simply as possible.
Essentially, the role of the = in most cases is a combination of the
destructor and copy constructor, right? Is there an easy way to do
this (eg
A& A:perator = (A& a)
{
~A::A();
A::A(a);
}
I'd like to avoid defining = and copy constructors for all classes,
simply because in the case of D and E they'll call the base class'
function and then just do assignment to the passed class' members (and
it seems like the default behaviour should do that).
My solution for copy constructors was to provide one for B and A, and
have B call A. Then I thought that C, D, and E would just initialize
their members "memberwise", and call the base class copy constructor.
Is this right? How do I get assignments (=) to work then?
Sorry if I didn't explain very well. Thanks in advance for your help.
Russ
I'm trying to get inheritance and constructors clear in my head (and
in my code). I have the following inheritance situation (all
derivations public):
A is the base class
B is inherited from A
C is inherited from B
D is inherited from A
E is inherited from D.
Simple enough. Now here's the deal:
A's data is all basic data types (all doubles, to be precise).
B includes a CArray (which doesn't have a = that I understand).
C includes some more numbers.
D and E only include additional numbers.
The code I'm writing is complaining that there's no = operator defined
for a class D or E assignment. In essence, "memberwise copying" will
be fine for data in all classes except B, where I need to write some
code.
I want to make all assignments work as simply as possible.
Essentially, the role of the = in most cases is a combination of the
destructor and copy constructor, right? Is there an easy way to do
this (eg
A& A:perator = (A& a)
{
~A::A();
A::A(a);
}
I'd like to avoid defining = and copy constructors for all classes,
simply because in the case of D and E they'll call the base class'
function and then just do assignment to the passed class' members (and
it seems like the default behaviour should do that).
My solution for copy constructors was to provide one for B and A, and
have B call A. Then I thought that C, D, and E would just initialize
their members "memberwise", and call the base class copy constructor.
Is this right? How do I get assignments (=) to work then?
Sorry if I didn't explain very well. Thanks in advance for your help.
Russ