This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Namespace Lookup


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]