TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: CLIFF RHODES
from: BALOG PAL
date: 1997-04-16 03:59:00
subject: inheritance in C++

                              Hi, Cliff Rhodes!
On 09 Apr 97  16:11:04 you wrote to Balog Pal
 BP> WV> class Derived : public Base
 BP> WV> {
 BP> WV> typedef Base Inherited;
 BP> WV> };
 BP>
 BP>Hm, this really solves some of my problems. I didn't notice before
 BP>that typedef also can be scoped in a class.
 CR> Paul or Wim, I missed some of this thread. What is the benefit to you
 CR> of  using this typedef? I'm curious what problem it solves. Thanks.
Well. When you use a class library you time to time face the problem that
some of your derived classes need a parent change. Eg. you decide a
SortedCollection can be used instead of simple Colection, or you developed a
specialised Dialog with singigng Help button and want to refit old Dialog
derived stuff to use this instead.
It would not be a problem if you could sinply go to the class definition,
change the class after : and ready. A plenty of overridden functuins make
calls to the parent's similar function just to add some functionality before
or after that. And you must precisely replace all those calls to use the new
parent. In most cases you will not even get a warning from the compiler
missing one or two, but you'll likely have funny runtime bugs. ;)
The other painful thing is when you write the functions just mentioned. As
you must specify the parent name you must know it by heart or look up in the
header. (And if you use an app framework like MFC tha latter case is likely.
:)
The only solution for that problems I knew before was to use a #undef/#define
PARENT. But to use it you probably must take extreme care how you place your
implementation functions in the module, and how you include header files. In
some cases you may end up to use someone elese's parent and gain the same
problems mentioned above.
Using that scoped typedef really solves the problem, you just modify the
parent in two places located 1-2 lines to each other. And the scoping make
all your class functions use the correct parent in the implementation. :-)
Paul
... An electrical engineer deals with current events
--- OS/2 Warp
---------------
* Origin: The FlintStones' Cave in BedRock (2:371/20)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.