Topic: Overloading of inherited operations (C


Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/11/14
Raw View
In article E9768200@slip3-24.acs.ohio-state.edu, Sergey Zhupanov <sergey@cis.ohio-state.edu> writes:
>
> ...
>
>The main reason this works is that here we know the number and the names of
>the operations we are inheriting (and overloading.)  Consider, however, a
>more general case, in which neither of these are known:
>
>template <class Parent_1, class Parent_2>
>class Child : public Parent_1, public Parent_2
>{
>public:
>   // Desired: Interface of Child to be the UNION of
>   //          interfaces of Parent_1 and Parent_2.
>};
>
>Is it possible to say anything in the public section of Child to make the
>above "wish" be a reality?  In other words, is it possible to make the
>interface of Child export the overloaded operations from Parents'
>interfaces?  For example, can Child export both Parent_1::foo(int) and
>Parent_2::foo(char) WITHOUT KNOWING their names or even the number of such
>overloadings that would take place?

No, it isn't possible. The question that occurs to me is why you would
need such a feature. Apparently you don't know anything about the
interfaces of the two base classes, but you do know that you want
mix them. How could you know that? In addition, suppose each one
has a type (or data) member x. You want them brought into the same scope?

It does make sense to document that each base class must have, for example,
one or more function members called foo with certain characteristics.
You could then write
 using Parent_1::foo;
 using Parent_2::foo;
and have some idea of the consequences of what you were doing.

But I don't understand why you would want to mix unconditionally the
interfaces of two classes about which you know nothing. Do you also remove
all the labels from all the packages you buy at the supermarket before
putting them away in the pantry?
---
Steve Clamage, stephen.clamage@eng.sun.com



---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]