Article View: comp.std.c++
Article #2557Re: Overloading of inherited operations?
From: Steve Clamage
Date: Tue, 14 Nov 1995 21:05
Date: Tue, 14 Nov 1995 21:05
64 lines
2592 bytes
2592 bytes
In article 779@aztec.co.za, dharley@aztec.co.za (David Harley) writes:
>
>Steve Clamage (clamage@Eng.Sun.COM) wrote:
>
>: A using-directive will solve your problem without generating any extra code.
>
>: class B1 { public: int foo(int); };
>: class B2 { public: int foo(char); };
>: class D : public B1, public B2 {
>: public:
>: using B1::foo; // "using" applies to a name, not to a signature
>: using B2::foo;
>: double foo(double); // new overload
>: };
>
>[ snip ]
>
>I have never understood why an overloaded member of a subclass hides a
>superclass's member. It seems to be illogical and contradicts the
>behaviour of non-class members. (It is also very irritating.)
The fundamental rule of scopes is that a name declared in a scope hides
all instances of that name in all outer scopes. Therefore, overloading
cannot occur across scopes. Base class scope is a different scope from
derived class scope, and encloses the derived class scope.
If overloading could occur across scopes, you would need a lot of special
rules. Example:
class A { ... int f(int); };
class B : public A { ... char* f; };
class C : public B { ... double f(double); };
A a;
B b;
C c;
a.f(1) // OK, call A::f(int)
b.f[0] // OK, access B::f
b.f(1) // If OK, why? If not, why not?
c.f(1.0) // OK, call C::f(double)
c.f[0] // If OK, why? If not, why not?
c.f(1) // call C::f(double) or A::f(int), and why?
This simple example would require special-case rules if we don't keep the
existing fundamental rule of scopes.
>What is 'using'? It does not seem to be standard.
It was added to the C++ draft standard 2 or 3 years ago. You can read about
it in the discussion of namespaces in "The Design and Evolution of C++" or
in the public-review copy of the draft standard which was posted on
several public FTP sites last May.
---
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. ]
Technical Details
Message-ID:
<48b03a$2h4@engnews1.eng.sun.com>Path:
arc1-ca.pugleaf.net!128.32.155.1!mattReferences:
<48adgo$779@aztec.co.za>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt From: clamage@Eng.Sun.COM (Steve Clamage) Newsgroups: comp.std.c++ Subject: Re: Overloading of inherited operations? Date: 14 Nov 1995 21:05:11 GMT Organization: Sun Microsystems Inc. Approved: matt@physics10.Berkeley.EDU (Matt Austern) Message-ID: <48b03a$2h4@engnews1.eng.sun.com> References: <48adgo$779@aztec.co.za> Reply-To: clamage@Eng.Sun.COM NNTP-Posting-Host: physics10.berkeley.edu