🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by Sergey Zhupanov Tue, 14 Nov 1995 20:34
RE: Overloading of inherited operations (Continued Discussion)
#2584
Author: Sergey Zhupanov
Date: Tue, 14 Nov 1995 20:34
55 lines
2126 bytes
First I would like to thank all the folks who kindly replied to my original 
posting.  The newly introduced "using" directive does indeed solve the 
problem for the case of the two simple examples I provided.

For example:

class P1 { public: void foo (int); };
class P2 { public: void foo (char); };
class C: public P1, public P2
{
public:
   using P1::foo;
   using P2::foo;
   void foo (double);
};

makes C export all three overloaded operations: foo(char), foo(int), and 
foo(double).

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?

Thanks very much,
  sergey

sergey@cis.ohio-state.edu

Graduate Research Assistant,
Computer and Information Science Department,
The Ohio State University




---
[ 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. ]
Re: Overloading of inherited operations (C
#2565
Author: Steve Clamage
Date: Tue, 14 Nov 1995 23:08
50 lines
2587 bytes
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. ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads