Re: [Dev-C++] operator+ and inheritance
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Stanley <sms...@iw...> - 2004-05-09 17:33:28
|
--- On Sun 05/09, =?ISO-8859-2?Q?OROSZI_Bal=E1zs?= < or...@vp... > wrote: From: =?ISO-8859-2?Q?OROSZI_Bal=E1zs?= [mailto: or...@vp...] To: dev...@li... Date: Sun, 09 May 2004 13:07:44 +0200 Subject: Re: [Dev-C++] operator+ and inheritance 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. 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. 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 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. 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 _______________________________________________ |