Article View: comp.std.c++
Article #1715Re: STL operators != > <= >=
From: Etay Bogner
Date: Fri, 11 Aug 1995 03:23
Date: Fri, 11 Aug 1995 03:23
80 lines
3376 bytes
3376 bytes
You did NOT understand.
The reason N1::f() should be choosen is because it's in the SAME namespace
as N1:g(), and NOT because it was declared before N2:f().
That's why I gave the paralel "global function versus member function" name
resolution example.
The Examples AGAIN ( somewhat re-ordered for clarity ) :
namespace N1 { // re-ordered for clarity
void g();
};
namespace N2 {
void f();
};
namespace N1 { // moved here for clarity
void f();
};
using namespace N1;
using namespace N2;
void N1::g() {
f(); // here is the BUG in the language. Should use N1::f(). See
Below.
}
The paralel "global function versus member function" name resolution :
void f();
class X {
void f();
void g();
};
void X::g() {
f(); // here it's OK. calls X::f() and NOT ::f()
}
Just think of a namespace as a class declaration.
In the second example, X::f() is choosen simply because it's in the SAME
scope as X::g().
So why not do so for namespaces ?
I think this is a logical solution to the problem of name resolution between
namespaces. It does NOT intreduce new problems, since we already know that
the same name resolution method is used with global functions and classes,
as shown in the second example.
Since, for instance, only one "void f()" can exists in a namespace ( as in a
class ), the language can choose N1::f() simply because it's in the SAME
namespace as the calling function, N1:g(), and can make a "bad thing" since
the rules are clear ( and already working ).
And again, this is EXACTLY what happens in the second example, X::f() is
choosen simply because it's in the SAME name scope as the calling function,
in this case X::g().
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.
HTH,
Will someone send this proposed correction to the draft to the standard
committe ?
-- Etay Bogner,
-- Etay_Bogner@mail.stil.scitex.com,
-- Scitex Corp.
-- Israel.
Technical Details
Message-ID:
<40ebdo$5on@lyman.pppl.gov>Path:
arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamageReferences:
<3vpmv5$4t7@mujibur.inmind.com> <3vpnrq$50c@mujibur.inmind.com> <MATT.95Aug7100148@godzilla.EECS.Berkeley.EDU> <4065oq$3f4@mujibur.inmind.com> <407n9d$nb7@lyman.pppl.gov> <409bjt$59c@mujibur.inmind.com> <40ba9d$5ij@lyman.pppl.gov> <40brjt$343@mujibur.inmind.com> <40cbmh$liu@lyman.pppl.gov> <40dnej$spe@mujibur.inmind.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage From: Etay Bogner <Etay_Bogner@mail.stil.scitex.com> Newsgroups: comp.std.c++ Subject: Re: STL operators != > <= >= Date: 11 Aug 1995 03:23:34 GMT Organization: Scitex Corp. Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <40ebdo$5on@lyman.pppl.gov> References: <3vpmv5$4t7@mujibur.inmind.com> <3vpnrq$50c@mujibur.inmind.com> <MATT.95Aug7100148@godzilla.EECS.Berkeley.EDU> <4065oq$3f4@mujibur.inmind.com> <407n9d$nb7@lyman.pppl.gov> <409bjt$59c@mujibur.inmind.com> <40ba9d$5ij@lyman.pppl.gov> <40brjt$343@mujibur.inmind.com> <40cbmh$liu@lyman.pppl.gov> <40dnej$spe@mujibur.inmind.com> NNTP-Posting-Host: taumet.eng.sun.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nntp-Posting-Host: applepo8.scitex.com X-Mailer: Mozilla 1.1N (Macintosh; I; PPC) To: mfinney@inmind.com X-Url: news:40dnej$spe@mujibur.inmind.com Content-Length: 2313 Originator: clamage@taumet