Article View: comp.std.c++
Article #1784Re: template operators <,>,!=
From: John Max Skaller
Date: Tue, 15 Aug 1995 02:59
Date: Tue, 15 Aug 1995 02:59
57 lines
2173 bytes
2173 bytes
In article <40ebvt$88f@lyman.pppl.gov>,
Etay Bogner <Etay_Bogner@mail.stil.scitex.com> wrote:
>You did NOT understand.
Neither did you!
>namespace N1 { void g(); };
>namespace N2 { void f(); };
>namespace N1 { void f(); };
>
>using namespace N1;
>using namespace N2;
>
>void N1::g() {
> f(); // here is the BUG in the language. Should use N1::f().
There's no bug. It DOES use N1::f().
> }
>
>This will solve the problem of defining the template operator <,>,!=
>etc. functions if the classes that USES your classes will be in the SAME
>namespace as your classes, thus the calls for those template function
>will resolve to YOUR functions, instead of STL's, and this is simply (
>everything is simple here ? ) because they are in the SAME namespace as
>your templates.
BE CAREFUL! We're talking about HIDING here. Consider:
namespace A { class U {}; void f(U); }
using namespace A;
namespace B {
class V {};
void f(V);
void k() {
U u;
f(u); // ERROR!
}
}
It's an ERROR here because f is B::f and the only visible
signature is f(V).
This DOESN'T happen for operator symbols, where a new rule
says lookup continues into the namespace of the
types of the arguments before overload resolution.
(proposed by Andrew Koenig, so I call this "Koenig Lookup")
--
JOHN (MAX) SKALLER, INTERNET:maxtal@suphys.physics.su.oz.au
Maxtal Pty Ltd,
81A Glebe Point Rd, GLEBE Mem: SA IT/9/22,SC22/WG21
NSW 2037, AUSTRALIA Phone: 61-2-566-2189
---
[ 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:
<40o0e4$1c6@metro.ucc.su.OZ.AU>Path:
arc1-ca.pugleaf.net!in2.uu.net!bounce-backReferences:
<40ebvt$88f@lyman.pppl.gov>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back Date: 15 Aug 95 02:59:19 GMT Approved: fjh@cs.mu.oz.au Return-Path: <daemon@ncar.UCAR.EDU> From: maxtal@Physics.usyd.edu.au (John Max Skaller) Newsgroups: comp.std.c++ Subject: Re: template operators <,>,!= X-Original-Date: 14 Aug 1995 17:16:52 GMT Organization: School of Physics, University of Sydney, Australia Message-ID: <40o0e4$1c6@metro.ucc.su.OZ.AU> References: <40ebvt$88f@lyman.pppl.gov>