Topic: Inheriting Overloaded Functions


Author: johnt@meaddata.com (John Townsend)
Date: 23 Aug 91 16:17:21 GMT
Raw View
Please consider the following three little classes:

   class A {
      virtual void a (Foo);
      virtual void a (Bar);
      virtual void b ();
   };
   class B: public A {
      virtual void a (Foo);
   };
   class C: public B {
      virtual void a (Foo);
      virtual void a (Bar);
   };

Now suppose that in the definition of C::a(Bar), I want to call the function
that it is overridding.  The parent class of C, which is B, does not override
the function A::a(Bar), and so inherits it as-is.  Is it correct to call the
function B::a(Bar) from within the definition of C::a(Bar) (or anywhere else,
for that matter)?  If not, what if B later decides to override its a(Bar)
function?  Then C::a(Bar) is no longer calling its parent class's function if
it calls A::a(Bar) directly.  If so, our AT&T compiler is at fault for
incorrectly attempting to call B::a(Foo) and reporting a type mismatch error
(because a Bar is not a Foo) when it should resolve the call to A::a(Bar).  It
will, however, allow calls to B::b() without complaint.

If you can shed some light on this problem, please let me know.  If possible,
please refer me to the ARM.

--
John Townsend                     Internet:   johnt@meaddata.com
c/o Mead Data Central             UUCP:       ...!uunet!meaddata!johnt
9555 Springboro Pike              GEnie:      J.E.TOWNSEND
Miamisburg, OH  45342             Telephone:  (513) 865-7250
                                  Telefax:    (513) 865-1655