title: boost::variant and printing methods of elements in vector
body: <pre><code> std::vector&lt; boost::variant&lt;std::string, int&gt; &gt; vec;
   std::string s1("abacus");
   int i1 = 42;
   vec.push_back(s1);
   vec.push_back(i1);
   std::cout &lt;&lt; vec.at(0).size() &lt;&lt; "\n";
  </code></pre>
  
  <p>when I try to run this code, I get the following error:</p>
  
  <pre><code>main.cpp:68: error: ‘class boost::variant&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, int, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_&gt;’ has no member named ‘size’
  make: *** [main.o] Error 1
  </code></pre>
  
  <p>however, being a string it should have a size() method. I'm not sure what is going wrong. note that replacing the last line with:</p>
  
  <pre><code>std::cout &lt;&lt; vec.at(0) &lt;&lt; "\n";
  </code></pre>
  
  <p>will print "abacus", as expected.</p>