Boost logo

Boost Users :

Subject: [Boost-users] [lexical_cast][variant] Compile failed when included boost.variant.
From: Tianjiao Yin (ytj000_at_[hidden])
Date: 2012-01-30 22:43:54


Hello, all:

I met a strange compile error, this code will reproduce the problem::

    #include <boost/lexical_cast.hpp>
    #include <boost/variant.hpp>
    #include <iostream>

    namespace foo {
    struct bar {};
    }

    std::ostream& operator << (std::ostream& out, foo::bar) {
        return out << "BAR";
    }

    int main() {
        boost::lexical_cast<std::string>(foo::bar());
    }

However, if I just remove that unused include boost.variant, it works::

    #include <boost/lexical_cast.hpp>
    //#include <boost/variant.hpp>
    #include <iostream>

    namespace foo {
    struct bar {};
    }

    std::ostream& operator << (std::ostream& out, foo::bar) {
        return out << "BAR";
    }

    int main() {
        boost::lexical_cast<std::string>(foo::bar());
    }

Another solution is put that "operator<<" in namespace foo::

    #include <boost/lexical_cast.hpp>
    #include <boost/variant.hpp>
    #include <iostream>

    namespace foo {
    struct bar {};
    std::ostream& operator << (std::ostream& out, foo::bar) {
        return out << "BAR";
    }
    } // namespace foo

    int main() {
        boost::lexical_cast<std::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 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