Hi!
Thanks for your answer.
I thought about direct access to the base class data, but the base class=20
is also usable "as is". The derived one only extends it with some more=20
info. I already defined an operator+ for the base, so I didn't want to=20
duplicate the same code in the derived class' operator+.
--
Greetings,
Bal=E1zs
Stanley wrote:
> --- On Sun 05/09, =3D?ISO-8859-2?Q?OROSZI_Bal=3DE1zs?=3D < oroszib@vpg=
.sulinet.hu > wrote:
> From: =3D?ISO-8859-2?Q?OROSZI_Bal=3DE1zs?=3D [mailto: or...@vp...=
et.hu]
> To: dev...@li...
> Date: Sun, 09 May 2004 13:07:44 +0200
> Subject: Re: [Dev-C++] operator+ and inheritance
>=20
> A lot depends on how you want to handle it. If you declare
> your base data as private, then you'll have to call your
> base class operator+ in order to access the sum of the
> data in the base class.
>=20
> However; you can also declare your data in the base class
> to be protected, in which case you can access and modify
> your base class data directly.
>=20
> Which method you use is a desing decision. Do you want to hide
> your data as much as possible? Or is convienent access to your=20
> data from the derived class more important? If your operator+
> is the only method that need direct access to your base data,
> then using the base class operator+ is probably a good way
> to implement the class. If your derived class needs access to
> the base class in a lot of methods, the going with protected
> data is probably better.
>=20
> And, of course, a third solution is to provide a set of protected
> inlined mutator/accessors so that your derived class(es) have full
> access to your base class data, but other classes do not. This
> is a lot more work, but a purist would probably take that as the
> best solution.
> TTFN
> Stanley
|