M
morten
When i compile this code in VC71 or VC80 i get the following errors:
The code is copy/paste from the boost.org tutorial. Please help!
error C2039: 'begin' : is not a member of 'boost::variant<T0_,T1>'
with
[
T0_=int,
T1=std::string
]
Test2.cpp(47): error C2039: 'end' : is not a member of
'boost::variant<T0_,T1>'
with
[
T0_=int,
T1=std::string
]
Test2.cpp(47): error C2039: 'begin' : is not a member of
'boost::variant<T0_,T1>'
with
[
T0_=double,
T1=std::string
]
"
#include "boost/variant.hpp"
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
class are_strict_equals
: public boost::static_visitor<bool>
{
public:
template <typename T, typename U>
bool operator()( const T &, const U & ) const
{
return false; // cannot compare different types
}
template <typename T>
bool operator()( const T & lhs, const T & rhs ) const
{
return lhs == rhs;
}
};
int main(int argc, char* argv[])
{
boost::variant< int, std::string > v1( "hello" );
boost::variant< double, std::string > v2( "hello" );
assert( boost::apply_visitor(are_strict_equals(), v1, v2) );
boost::variant< int, const char * > v3( "hello" );
assert( !boost::apply_visitor(are_strict_equals(), v1, v3) );
typedef boost::variant<double, std::string> my_variant;
std::vector< my_variant > seq1;
seq1.push_back("pi is close to ");
seq1.push_back(3.14);
std::list< my_variant > seq2;
seq2.push_back("pi is close to ");
seq2.push_back(3.14);
are_strict_equals visitor;
assert( std::equal(v1.begin(), v1.end(), v2.begin(),
boost::apply_visitor( visitor ) ) );
return 0;
}
The code is copy/paste from the boost.org tutorial. Please help!
error C2039: 'begin' : is not a member of 'boost::variant<T0_,T1>'
with
[
T0_=int,
T1=std::string
]
Test2.cpp(47): error C2039: 'end' : is not a member of
'boost::variant<T0_,T1>'
with
[
T0_=int,
T1=std::string
]
Test2.cpp(47): error C2039: 'begin' : is not a member of
'boost::variant<T0_,T1>'
with
[
T0_=double,
T1=std::string
]
"
#include "boost/variant.hpp"
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
class are_strict_equals
: public boost::static_visitor<bool>
{
public:
template <typename T, typename U>
bool operator()( const T &, const U & ) const
{
return false; // cannot compare different types
}
template <typename T>
bool operator()( const T & lhs, const T & rhs ) const
{
return lhs == rhs;
}
};
int main(int argc, char* argv[])
{
boost::variant< int, std::string > v1( "hello" );
boost::variant< double, std::string > v2( "hello" );
assert( boost::apply_visitor(are_strict_equals(), v1, v2) );
boost::variant< int, const char * > v3( "hello" );
assert( !boost::apply_visitor(are_strict_equals(), v1, v3) );
typedef boost::variant<double, std::string> my_variant;
std::vector< my_variant > seq1;
seq1.push_back("pi is close to ");
seq1.push_back(3.14);
std::list< my_variant > seq2;
seq2.push_back("pi is close to ");
seq2.push_back(3.14);
are_strict_equals visitor;
assert( std::equal(v1.begin(), v1.end(), v2.begin(),
boost::apply_visitor( visitor ) ) );
return 0;
}