This is the mail archive of the gcc-bugs@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]
Other format: [Raw text]

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


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