Article View: comp.std.c++
Article #2568Re: Overloading of inherited operations?
From: Fergus Henderson
Date: Mon, 13 Nov 1995 17:16
Date: Mon, 13 Nov 1995 17:16
52 lines
2057 bytes
2057 bytes
Sergey Zhupanov <sergey@cis.ohio-state.edu> writes:
>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!
You can solve this problem with a `using' declaration.
class B : public A { public: using A::foo; void foo (char c); };
^^^^^^^^^^^^^
Now the two definitions of `foo' will be overloaded.
See section 7.3.3 [namespace.udecl] of the draft standard,
which includes an example that is almost identical to the above.
>Example 2:
>---------
>
>class A { public: void foo (int i); }
>class B { public: void foo (char c); }
>class C : public A, public B {};
Again, you can use `using' declarations to solve the problem:
class C : public A, public B {
public:
using A::foo;
using B::foo;
};
Of course, whether or not the compiler you are currently using
supports `using' declarations yet is another question... they
are a relatively new feature (introduced along with namespaces)
and many compilers don't yet support them.
--
Fergus Henderson WWW: http://www.cs.mu.oz.au/~fjh
fjh@cs.mu.oz.au PGP: finger fjh@128.250.37.3
---
[ 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:
<9531723.9653@mulga.cs.mu.OZ.AU>Path:
arc1-ca.pugleaf.net!128.32.155.1!mattReferences:
<01BAB117.021F9BA0@slip6-2.acs.ohio-state.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson) Newsgroups: comp.std.c++ Subject: Re: Overloading of inherited operations? Date: 13 Nov 1995 17:16:45 GMT Organization: Computer Science, University of Melbourne, Australia Approved: matt@physics2.Berkeley.EDU (Matt Austern) Message-ID: <9531723.9653@mulga.cs.mu.OZ.AU> References: <01BAB117.021F9BA0@slip6-2.acs.ohio-state.edu> NNTP-Posting-Host: physics2.berkeley.edu