This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Namespace Lookup
- To: egcs at cygnus dot com
- Subject: Re: Namespace Lookup
- From: "Lassi A. Tuura" <lat at iki dot fi>
- Date: Tue, 10 Mar 1998 09:06:14 +0100 (MET)
- Reply-To: "Lassi A. Tuura" <Lassi dot Tuura at cern dot ch>
Martin von Loewis wrote:
|> Is the following correct C++? If so, why? I.e. why is the operator<<
|> visible?
|> class ostream; extern ostream cout;
|> namespace foo {
|> struct S { int i; }; extern ostream &operator<<(ostream &, const S &);
|> }
|> void bar(foo::S s) { cout << s ; }
The code is correct due to the Koenig lookup rules: for an unqualified
function name (`operator<<' in `bar'), suitable candidates for overload
resolution are searched, among other places, from the namespaces of the
argument types (in this particular case, `foo'; `std' would also be
searched if `ostream' was conforming). For more details see the section
`[basic.lookup.koenig]' (``3.4.2 Argument-dependent name lookup'' in
Dec'96 draft).
Cheers,
//lat
--
Every old idea will be proposed again with a different name and a
different presentation, regardless of whether it works. --RFC1925