Link to home
Create AccountLog in
Avatar of vileda
vileda

asked on

No match for operator "<<"

Hello,
Im trying to compile boost's variant example which is given in boost web site.

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

class my_visitor : public boost::static_visitor<int>
{
public:
    int operator()(int i) const
    {
        return i;
    }
    
    int operator()(const std::string & str) const
    {
        return str.length();
    }
};

int main()
{
    boost::variant< int, std::string > u("hello world");
    std::cout << u; // output: hello world

    int result = boost::apply_visitor( my_visitor(), u );
    std::cout << result; // output: 11 (i.e., length of "hello world")
}

Open in new window


But it gives an error like this

No match for operator "<<" ...    ...   ....     variant_io.hpp

What could be the problem?

Kind regards
Avatar of HappyCactus
HappyCactus
Flag of Italy image

Here it compiles and work fine:

HappyCactus$ g++ --version
i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5659)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

anaconda:b HappyCactus$ grep BOOST_LIB_VERSION /usr/local/include/boost/version.hpp
//  BOOST_LIB_VERSION must be defined to be the same as BOOST_VERSION
#define BOOST_LIB_VERSION "1_44"
anaconda:b HappyCactus$

Check carefully your compilation options and the include path. If you have multiple version of boost, remove all but the most recent. and upgrade boost.
ASKER CERTIFIED SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of vileda
vileda

ASKER

I'm trying to compile it from QNX Momentics Windows version. The include path seems ok and I have only one version.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.