Opened 12 years ago
Closed 7 years ago
#4681 closed Feature Requests (fixed)
can't serialize protected derived class
Reported by: | Owned by: | Robert Ramey | |
---|---|---|---|
Milestone: | To Be Determined | Component: | serialization |
Version: | Boost 1.40.0 | Severity: | Problem |
Keywords: | Cc: |
Description
The attached code won't compile because wrapper::derived is a protected member of the wrapper class.
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.
Attachments (1)
Change History (7)
by , 12 years ago
comment:1 by , 12 years ago
Hmmm, it would be nice if you could share your workaround. Is it something that could be just rolled into export.hpp?
Robert Ramey
comment:2 by , 12 years ago
I took BOOST_CLASS_EXPORT_GUID and split it into two macros, removing the namespace bits:
#define BOOST_CLASS_EXPORT_PROTECTED_1(T) \ static ::boost::archive::detail::guid_initializer< T > const \ & guid_initializer; \ #define BOOST_CLASS_EXPORT_PROTECTED_2(W, T, K) \ ::boost::archive::detail::guid_initializer< W::T > const & \ W::guid_initializer = \ ::boost::serialization::singleton< \ ::boost::archive::detail::guid_initializer< W::T > \ >::get_mutable_instance().export_guid(K) \ /**/ class foo { protected: class bar { // ... }; BOOST_CLASS_EXPORT_PROTECTED_1(foo::bar) }; BOOST_CLASS_EXPORT_PROTECTED_2(foo, bar, "foo::bar")
comment:3 by , 12 years ago
This workaround doesn't, in fact, work around. I don't understand what's going on well enough to make it work.
comment:4 by , 12 years ago
I looked at this a little bit and I don't see any easy fix.
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.
Robert Ramey
comment:5 by , 12 years ago
Status: | new → assigned |
---|
comment:6 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
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.
demonstration of the problem with serializing protected classes