c++/7049: Overloading "cout <<" in one namespace obscures similar functions in a different namespace
steev@paradigmds.com
steev@paradigmds.com
Mon Jun 17 02:46:00 GMT 2002
>Number: 7049
>Category: c++
>Synopsis: Overloading "cout <<" in one namespace obscures similar functions in a different namespace
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Jun 17 01:46:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Steev Wilcox
>Release: 3.1 (sparc-sun-solaris2.8)
>Organization:
>Environment:
Solaris 8
>Description:
If you define a operator<<(ostream&,thing) for an object X in one namespace, then in another namespace, define the same sort of function for a different object Y, it hides the original function so you can't print objects of type X in the namespace associated with object Y.
Fairly obvious workaround: don't define operator<<'s in namespaces - make sure they always go in the global namespace. Bjarne wouldn't be pleased, though. I'm not 100% certain this is a bug and not a "feature" of C++ - it just looks suspicious.
I haven't been able to find this in the list of known bugs, but it doesn't mean it's not there.
Thanks for your time, Steev
>How-To-Repeat:
Compile bug2.cpp with "g++ -c bug2.cpp". It'll fail in the way indicated in file "testout". If you place the definition of the operator<< on Y in the global namespace, g++ can suddenly find the definition of operator<< on X.
>Fix:
For workaround, see above.
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list