Problem overriding save_construct_data when serializing a class pointer without a default constructor

I am trying to follow this example http://www.boost.org/doc/libs/1_42_0/libs/serialization/doc/serialization.html#constructors , but I keep getting errors. After the example, I get an error trying to access a private variable (fairly fairly):

bs.cpp:10: error: ‘const int my_class::m_attribute’ is private

But, if I add save_construct_data as a friend, I get an ambiguity error:

/usr/include/boost/serialization/serialization.hpp:148: error: call of overloaded ‘save_construct_data(boost::archive::text_oarchive&, const my_class*&, const boost::serialization::version_type&)’ is ambiguous
/usr/include/boost/serialization/serialization.hpp:83: note: candidates are: void boost::serialization::save_construct_data(Archive&, const T*, unsigned int) [with Archive = boost::archive::text_oarchive, T = my_class]
bs.cpp:10: note:                 void boost::serialization::save_construct_data(Archive&, const my_class*, unsigned int) [with Archive = boost::archive::text_oarchive]
bs.cpp:29: note:                 void boost::serialization::save_construct_data(Archive&, const my_class*, unsigned int) [with Archive = boost::archive::text_oarchive]

I can move a function definition into a friend declaration, but it is just ugly.

What should I do next?

Thanks Jayen

+3
source share
2

save_construct_data , . - . :

namespace boost { namespace serialization {
template<class Archive>
inline void save_construct_data(Archive & ar, const my_class * t, const unsigned int file_version);
}}

my_class, my_class:

class my_class;

, http://pastebin.com/embed_iframe.php?i=aFyCpjyY

+6

, save_construct_data , , (boost:: serialization)

save_construct_data , boost ,

-1

Source: https://habr.com/ru/post/1773361/


All Articles