I have a boost variant with 7 types in it. When I try to use the last two types, the linker segfaults. I am using g++ (gcc version 3.3.3 on SuSE Linux) on a 64 bit linux machine and the error that I get is
collect2: ld terminated with signal 11 [Segmentation fault]
It doesnt matter what order I put the types in, the last two will cause a segfault when I try to use them. Any ideas why this would be happening?
Code:
typedef boost::tuple<std::string, Class1::Ptr> Class1Tuple;
typedef boost::tuple<std::string, Class2::Ptr> Class2Tuple;
typedef boost::tuple<std::string, Class3::Ptr> Class3Tuple;
typedef boost::tuple<std::string, Class4::Ptr> Class4Tuple;
typedef boost::tuple<std::string, Class5::Ptr> Class5Tuple;
typedef boost::tuple<std::string, Class6::Ptr> Class6Tuple;
typedef boost::tuple<std::string, Class7::Ptr> Class7Tuple;
typedef boost::variant< Class1Tuple, Class2Tuple, Class3Tuple,
Class4Tuple, Class5Tuple, Class6Tuple,
Class7Tuple > ClassTupleItem;
ClassX::Ptr is a boost shared pointer to that class. Ptr is defined as a typedef inside the class itself as below
struct Class1
{
typedef boost::shared_ptr<Class1> Ptr;
...
...
}
when I try to use the last two types in the boost variant as in
Class1Tuple tup("str", pointer);
ClassTupleItem(tup); // works fine since I used Class1Tuple
Class6Tuple tup2("str", pointer2);
ClassTupleItem(tup2); // causes a segfault.
if I define the boost::variant as (interchange Class6 and Class1)
typedef boost::variant< Class6Tuple, Class2Tuple, Class3Tuple,
Class4Tuple, Class5Tuple, Class1Tuple,
Class7Tuple > ClassTupleItem;
then I get a segfault when compiling this code
Class1Tuple tup("str", pointer);
ClassTupleItem(tup); // worked earlier