Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-04-13 08:15:44


Matt Hortman wrote:
> Hello,
>
> I feel almost silly asking this but:
>
> I can only get the code listed below to compile if I remove the
> comments on the namespace statements, placing my custom operator<< in
> the boost::detail::variant namespace. Otherwise I get the error
>
> c:\Boost\include\boost-1_32\boost\variant\detail\variant_io.hpp(64) :
> error C2679: binary '<<' : no operator found which takes a right-hand
> operand of type 'const T1' (or there is no acceptable conversion)
>
> from VC++ 7.1 and a similar error from both gcc 3.3 and 3.4. I'm
> using boost 1.32 on both WinXP and FreeBSD. Looking at the code in
> variant_io.hpp, I see no reason why it should not work without the
> namespace statements. Is there something fundamental about namespaces
> that I don't understand?

The short answer is that operator<< for N::X will will only work reliably if
you place it in namespace N. In your case this means placing it in namespace
std. Adding overloads to namespace std is forbidden by the standard, but is
the only way that will work on compilers that implement standard-conforming
name lookup in templates.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net