Boost C++ Libraries: Ticket #4681: can't serialize protected derived class https://svn.boost.org/trac10/ticket/4681 <p> The attached code won't compile because wrapper::derived is a protected member of the wrapper class. </p> <p> I have a workaround, which will be to write my own macros to achieve the same effect as BOOST_CLASS_EXPORT_GUID in this case, but it'd be nice if the library worked out of the box in this case. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4681 Trac 1.4.3 mark.r.buda@… Thu, 23 Sep 2010 15:51:49 GMT attachment set https://svn.boost.org/trac10/ticket/4681 https://svn.boost.org/trac10/ticket/4681 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">c.cc</span> </li> </ul> <p> demonstration of the problem with serializing protected classes </p> Ticket Robert Ramey Sat, 25 Sep 2010 17:13:02 GMT <link>https://svn.boost.org/trac10/ticket/4681#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4681#comment:1</guid> <description> <p> Hmmm, it would be nice if you could share your workaround. Is it something that could be just rolled into export.hpp? </p> <p> Robert Ramey </p> </description> <category>Ticket</category> </item> <item> <author>mark.r.buda@…</author> <pubDate>Mon, 27 Sep 2010 15:25:03 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4681#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4681#comment:2</guid> <description> <p> I took BOOST_CLASS_EXPORT_GUID and split it into two macros, removing the namespace bits: </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#define BOOST_CLASS_EXPORT_PROTECTED_1(T) \</span> <span class="cp"> static ::boost::archive::detail::guid_initializer&lt; T &gt; const \</span> <span class="cp"> &amp; guid_initializer; \</span> <span class="cp">#define BOOST_CLASS_EXPORT_PROTECTED_2(W, T, K) \</span> <span class="cp"> ::boost::archive::detail::guid_initializer&lt; W::T &gt; const &amp; \</span> <span class="cp"> W::guid_initializer = \</span> <span class="cp"> ::boost::serialization::singleton&lt; \</span> <span class="cp"> ::boost::archive::detail::guid_initializer&lt; W::T &gt; \</span> <span class="cp"> &gt;::get_mutable_instance().export_guid(K) \</span> <span class="cm">/**/</span><span class="cp"></span> <span class="k">class</span> <span class="nc">foo</span> <span class="p">{</span> <span class="k">protected</span><span class="o">:</span> <span class="k">class</span> <span class="nc">bar</span> <span class="p">{</span> <span class="c1">// ...</span> <span class="p">};</span> <span class="n">BOOST_CLASS_EXPORT_PROTECTED_1</span><span class="p">(</span><span class="n">foo</span><span class="o">::</span><span class="n">bar</span><span class="p">)</span> <span class="p">};</span> <span class="n">BOOST_CLASS_EXPORT_PROTECTED_2</span><span class="p">(</span><span class="n">foo</span><span class="p">,</span> <span class="n">bar</span><span class="p">,</span> <span class="s">&quot;foo::bar&quot;</span><span class="p">)</span> </pre></div></div> </description> <category>Ticket</category> </item> <item> <author>mark.r.buda@…</author> <pubDate>Wed, 29 Sep 2010 16:28:29 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4681#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4681#comment:3</guid> <description> <p> This workaround doesn't, in fact, work around. I don't understand what's going on well enough to make it work. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Robert Ramey</dc:creator> <pubDate>Wed, 29 Sep 2010 16:56:18 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4681#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4681#comment:4</guid> <description> <p> I looked at this a little bit and I don't see any easy fix. </p> <p> I tried adding another friend to the protected class - but that doesn't work because init_guid is in an anonymous namespace. Of course you CAN work around by either not using a nested class or by making public (which I guess amounts to the same thing). Of course you don't want to do that. For now I'll just leave this open. </p> <p> Robert Ramey </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Robert Ramey</dc:creator> <pubDate>Sun, 03 Oct 2010 18:10:52 GMT</pubDate> <title>status changed https://svn.boost.org/trac10/ticket/4681#comment:5 https://svn.boost.org/trac10/ticket/4681#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket Robert Ramey Sun, 04 Oct 2015 17:53:40 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4681#comment:6 https://svn.boost.org/trac10/ticket/4681#comment:6 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Note; recently I've had occasion to look in to this. Turns out that one can serialization private and protected base classes - just not through pointers. I've added a case study to the documentation so explain this. I also investigated what it would take to make this work for pointers and concluded that it's not possible in the current library with current C++. So I'm going to close this item. </p> Ticket