Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with boost::variant, linker giving a segfault
    text
    copied!<p>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</p> <pre><code>collect2: ld terminated with signal 11 [Segmentation fault] </code></pre> <p>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?</p> <p>Code:</p> <pre><code>typedef boost::tuple&lt;std::string, Class1::Ptr&gt; Class1Tuple; typedef boost::tuple&lt;std::string, Class2::Ptr&gt; Class2Tuple; typedef boost::tuple&lt;std::string, Class3::Ptr&gt; Class3Tuple; typedef boost::tuple&lt;std::string, Class4::Ptr&gt; Class4Tuple; typedef boost::tuple&lt;std::string, Class5::Ptr&gt; Class5Tuple; typedef boost::tuple&lt;std::string, Class6::Ptr&gt; Class6Tuple; typedef boost::tuple&lt;std::string, Class7::Ptr&gt; Class7Tuple; typedef boost::variant&lt; Class1Tuple, Class2Tuple, Class3Tuple, Class4Tuple, Class5Tuple, Class6Tuple, Class7Tuple &gt; ClassTupleItem; </code></pre> <p>ClassX::Ptr is a boost shared pointer to that class. Ptr is defined as a typedef inside the class itself as below</p> <pre><code>struct Class1 { typedef boost::shared_ptr&lt;Class1&gt; Ptr; ... ... } </code></pre> <p>when I try to use the last two types in the boost variant as in</p> <pre><code>Class1Tuple tup("str", pointer); ClassTupleItem(tup); // works fine since I used Class1Tuple Class6Tuple tup2("str", pointer2); ClassTupleItem(tup2); // causes a segfault. </code></pre> <p>if I define the boost::variant as (interchange Class6 and Class1)</p> <pre><code>typedef boost::variant&lt; Class6Tuple, Class2Tuple, Class3Tuple, Class4Tuple, Class5Tuple, Class1Tuple, Class7Tuple &gt; ClassTupleItem; </code></pre> <p>then I get a segfault when compiling this code</p> <pre><code>Class1Tuple tup("str", pointer); ClassTupleItem(tup); // worked earlier </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload