Article View: comp.std.c++
Article #2591Re: Overloading of inherited operations (Conti
From: Steve Clamage
Date: Wed, 15 Nov 1995 18:21
Date: Wed, 15 Nov 1995 18:21
55 lines
2762 bytes
2762 bytes
In article 955@engnews1.eng.sun.com, Sergey Zhupanov <sergey@cis.ohio-state.edu> writes:
>
>After reading the relevant April draft section, I have a question regarding
>this issue.
>
>(1) Does an operation name brought into Child's scope by "using"
>declaration statement propagate further down the inheritance hierarchy?
Yes. A using-declaration for the purposes of name lookup and overloading
acts just like you had declared the name in that scope. (The
semantics here are really kludgy, but the net effect is probably
what you would intuitively expect.)
>Also, I just read in "The Evolution of C++" that a using directive, e.g.
>
> using namespace Parent;
>
>does not bring the names exported by Parent into scope, but merely makes
>them accessible, so I understand that the using directive would not help
>here either.
A using-directive ("using namespace ...") has truly bizarre
semantics, but lets you mix potentially conflicting declarations
without causing an error unless you try to use a conflicting name.
For example:
namespace N1 { int x; int foo(int); }
namespace N2 { double x; int foo(double); }
using namespace N1;
using namespace N2; // OK, even with potential conflict
...
foo(1); // OK, N1::foo
foo(1.0); // OK, N2::foo
int i = N1::x; // OK
int j = x; // error, there are two things called x
Overloading does occur across using-directives (as in the above example),
but won't help you with classes. You can only refer to a namespace
name, not a class name, with a using-directive, and you can't
put a using-directive in a class declaration. (Well, I'm pretty sure
you can't put a using-directive in a class declaration.)
>Finally, to address Steve's witty question regarding the grocery labels ...
I'm glad you took that as a joke. Upon re-reading it, I realized it
could possibly be interpreted as a flame, which was not my intent.
---
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:
<48dadr$8pv@engnews1.eng.sun.com>Path:
arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamageReferences:
<48d5bl$955@engnews1.eng.sun.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage From: clamage@Eng.sun.com (Steve Clamage) Newsgroups: comp.std.c++ Subject: Re: Overloading of inherited operations (Conti Date: 15 Nov 1995 18:21:13 GMT Organization: Sun Microsystems Inc. Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <48dadr$8pv@engnews1.eng.sun.com> References: <48d5bl$955@engnews1.eng.sun.com> Reply-To: clamage@Eng NNTP-Posting-Host: taumet.eng.sun.com Content-Type: text X-Nntp-Posting-Host: taumet.eng.sun.com Content-Length: 1923 X-Lines: 51 Originator: clamage@taumet