This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/7049 Overloading "cout <<" in one namespace obscures similar functions in a different namespace
- From: Philip Martin <philip at codematters dot co dot uk>
- To: steev at paradigmds dot com, gcc-gnats at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, gcc-bugs at gcc dot gnu dot org, nobody at gcc dot gnu dot org
- Date: 18 Jun 2002 12:30:14 +0100
- Subject: Re: c++/7049 Overloading "cout <<" in one namespace obscures similar functions in a different namespace
This is not a bug, that's how name lookup works.
The compiler will lookup operator<< in the anonymous namespace where
the statement "cout << x" occurs, the std:: namespace where ostream is
defined, and the ns:: namespace where class X is defined. Since the
compiler will find an operator<< by doing this it won't look anywhere
else. In particular operator<< in the global namespace will not be
considered.
Put operator<< for X where it belongs, in the ns:: namespace that
defines class X.
--
Philip