TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: CLIFF RHODES
from: WIM VELDHUIS
date: 1997-04-11 22:11:00
subject: inheritance in C++

Cliff Rhodes wrote in a message to Balog Pal:
--> Balog Pal wrote to Wim Veldhuis <--
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
 CR> benefit to you of  using this typedef? I'm curious what
 CR> problem it solves. Thanks. 
The benefit is that you define an alias for the ancestor class which means 
that you can use the alias in the class in which it is defined in stead of 
directly coding it. This makes a difference when you change the ancestor 
class (like inserting an extra layer in the inheritage tree). It also can be 
used to define another class like is done in the STL. There you use 
vector::iterator to specify a class which resolves to the class name of the 
iterator for a vector.
p.e.
class base
{
  public: virtual int foo(); { return 0; }
};
class Derived : public base
  typedef base Inherited;
  public :  virtual int foo();
};  
class  NewBase : public base
{
  public: virtual int foo() {return 10; }
};
int Derived::foo()
{
   return Inherited::foo() + 1;
}
If you change the inheritance so Derived descends from NewBase and you adjust 
the typedef in the class declaration, Derived::foo will call NewBase::foo().
If you have a lot of calls to the ancestor class this will increase 
maintainability a lot.
mvg/wr
  
--- timEd/2 1.01.g3+
---------------
* Origin: LightHouse BBS ==> I am a H.U.G.O. Member ! (2:285/324.3)

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™.