Article View: comp.std.c++
Article #2530Overloading of inherited operations?
From: Sergey Zhupanov
Date: Mon, 13 Nov 1995 07:04
Date: Mon, 13 Nov 1995 07:04
52 lines
2180 bytes
2180 bytes
Folks,
Can derived functions overload each other instead of hiding
or (worse yet) producing ambiguity? Trivial examples are:
Example 1:
---------
class A { public: void foo (int i); };
class B : public A { public: void foo (char c); };
Instead of overloading A::foo, B::foo hides it!
Example 2:
---------
class A { public: void foo (int i); }
class B { public: void foo (char c); }
class C : public A, public B {};
C exports both A::foo and B::foo but in a way that required fully-qualified
naming (e.g. c.A::foo(3)) to resolve ambiguity. Worse yet, one of the
inheritance links could even be private with same effect...
This is the way the language is defined to behave. Unfortunately, this
single "feature" prevents many interesting idioms from working. (I can
elaborate
if any one is interested.)
Commonly proposed solutions are:
-------------------------------
(1) re-defining the operation and using call-through (e.g. in example 1, B
would also define void foo (int i) that would call through to A::foo)
(2) Using fully qualified names (only helps in ambiguity with MI case)
However, for the situations I mentioned, these solutions are unacceptable.
My question is:
--------------
Does any one know of a way to make the above code (modified in some way)
behave in the way intended, as opposed to "the C++ way?"
Thanks very much in advance for your comments.
sergey
---
[ 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. ]
Technical Details
Message-ID:
<01BAB117.021F9BA0@slip6-2.acs.ohio-state.edu>Path:
arc1-ca.pugleaf.net!in2.uu.net!bounce-backShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back Date: 13 Nov 95 07:04:45 GMT Approved: fjh@cs.mu.oz.au Organization: - Newsgroups: comp.std.c++ Message-ID: <01BAB117.021F9BA0@slip6-2.acs.ohio-state.edu> From: Sergey Zhupanov <sergey@cis.ohio-state.edu> Subject: Overloading of inherited operations? X-Original-Date: Sun, 12 Nov 1995 15:53:21 -0500 Encoding: 49 TEXT X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMKbuK+EDnX0m9pzZAQFlEwGAozncm3bN74k2/8SvxUKGVNUHGtduOpXL bpRxmBplMkniWBj+hOA2imT31oiGoJ/8 =wSxy