Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I must admit I am not familiar with this <code>boost</code> package, but I copied and compiled the code, which produced the same result as the OP mentioned</p> <p>Realizing that we are using polymorphism, I added a <code>public: virtual ~A(){};</code> in <code>class A</code>. Also, <code>oa.register_type&lt;B&gt;();</code> is added in <code>main</code> according to the document, and output became:</p> <pre><code>A! B! </code></pre> <p>According to the specification, a class is a <code>polymorphic class</code> only when <code>declares or inherits a virtual function</code>. For non-polymorphic classed, maybe polymorphism just does not work.</p> <p>EDIT:</p> <p>Putting the <code>BOOST_CLASS_EXPORT(B);</code> in <code>B.cpp</code> instead of <code>B.h</code> seems to solve this problem of redefinition.</p> <p>EDIT:</p> <p>Checked the expansion result of <code>BOOST_CLASS_EXPORT(B)</code> (reformatted):</p> <pre><code>namespace boost { namespace serialization { template&lt;&gt; struct guid_defined&lt;B&gt; : boost::mpl::true_ {}; template&lt;&gt; inline const char * guid&lt;B&gt;(){ return "B"; } } } namespace boost { namespace archive { namespace detail { namespace { // NOTE template&lt;&gt; struct init_guid&lt; B &gt; { static guid_initializer&lt; B &gt; const &amp; g; }; guid_initializer&lt; B &gt; const &amp; init_guid&lt; B &gt;::g = ::boost::serialization::singleton&lt; guid_initializer&lt; B &gt; &gt;::get_mutable_instance().export_guid(); } } } } </code></pre> <p>And for the line marked with <code>NOTE</code>: for boost 1.42 used an anonymous namespace is used, which will be no problem if it is put into multiple cpp files or put into a header file (tested in ubuntu with g++, using the boost package come along with Ubuntu). However, in boost 1.48, <code>namespace extra_detail</code> is used, which would cause problems when put into multiple cpp files (tested in windows with VS2010, using boost downloaded from homepage).</p>
 

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