Templated insertion operators

Gabriel Dos Reis gdr@integrable-solutions.net
Fri Jan 30 20:40:00 GMT 2004


Dan Gregory <dan.gregory@mci.com> writes:

| When I move the operator<< into the namespace this problem goes away
| (so there's a workaround),

Well, I would not call it a workaround.

When you use the insertion operator (or any other operator for that
matter), the compiler looks into the current namespace and the
namespaces and classes associated with the arguments (hence the
terminology "argument-dependent name lookup") in search for matching
operator functions.  That means that you're most advised to put your
operations declarations (and therefore their definitions) in the
namespace that contains your types.  That is called the Interface
Principle. 

-- Gaby



More information about the Gcc-bugs mailing list