help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to copy map to ostream_iterator?


From: Thomas Maeder
Subject: Re: How to copy map to ostream_iterator?
Date: Thu, 04 May 2006 18:43:47 +0200
User-agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux)

"Siegfried" <siegfried@heintze.com> writes:

> Anyway, can anyone speculate with (for) me as to why the compiler
> (and c++ specification) works this way? It does not seem logical to
> only search the std namespace. It seems that writing application
> specific code for the std namespace should be forbidden.

[The question is: why does name lookup stop once the name is found in
a scope, even if this occurence doesn't fit.]

Consider this situation:

#include <iostream>

namespace myNamespace
{
  struct myStruct {}

  void f(myStruct const &) {}
}

int main()
{
  myNamespace::myStruct s;
  f(s);
}

Argument-dependant lookup says that f is first looked up in namespace
myNamespace; if the name f isn't found in namespace myNamespace, it is
looked up in the global namespace. This causes myNamespace::f to be
found an invoked, as everybody would expect.


Now what should we expect if somebody adds

void f(myStruct &) {}

in the global namespace, possibly in some remote header that is
indirectly #included. It would be very surprising if ::f would
suddenly be called.


That's why name lookup stops at the first scope where the name is
found.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]