[lexical_cast][variant] Compile failed when included boost.variant.

Hello, all:
I met a strange compile error, this code will reproduce the problem::
#include

On 31 January 2012 14:43, Tianjiao Yin
Hello, all:
I met a strange compile error, this code will reproduce the problem::
#include
#include #include <iostream> namespace foo { struct bar {}; }
std::ostream& operator << (std::ostream& out, foo::bar) { return out << "BAR"; }
int main() { boost::lexical_caststd::string(foo::bar()); }
However, if I just remove that unused include boost.variant, it works::
#include
//#include #include <iostream> namespace foo { struct bar {}; }
std::ostream& operator << (std::ostream& out, foo::bar) { return out << "BAR"; }
int main() { boost::lexical_caststd::string(foo::bar()); }
Another solution is put that "operator<<" in namespace foo::
#include
#include #include <iostream> namespace foo { struct bar {}; std::ostream& operator << (std::ostream& out, foo::bar) { return out << "BAR"; } } // namespace foo
int main() { boost::lexical_caststd::string(foo::bar()); }
Anyway, what is boost.variant's business here? Won't that fail to compile, or am I missing something? BTW, I'm using boost 1.48.0 and gcc 4.6.2 in Linux 3.2.2.
Regards, Tianjiao _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Your overloaded operator isn't found by ADL, which looks for it in namespaces std and foo. You should put it in the same namespace as your struct.
participants (2)
-
Tianjiao Yin
-
Vitaly Budovski