In short, combining a class implementation of serialize() with load/save_construct_data as described in the docs writes and reads data twice.
Varying the pattern can produce exceptions. My solution is to implement serialize() as a no-op and provide paired load/save_construct_data() functions. Is that actually a solution? Is there a better way?
The code at the bottom of this message yields
Microsoft C++ exception: boost::archive::archive_exception at memory location 0x000000B8189AC300.
When attempting to read in what was just written out.
Debugging shows that code attempts to read in the object twice, first in the class-specific
load_construct_data function I wrote, and then again in the instance method A::serialize. Since the save operation only wrote it out once, there is nothing, or at least nothing expected, to read and things go badly.
The documentation (https://www.boost.org/doc/libs/1_76_0/libs/serialization/doc/serialization.h...) says "If there is no such default constructor, the function templates load_construct_data and perhaps save_construct_data will have to be overridden." "perhaps" seems to imply that it is not essential to do so, and since the lack of a default constructor only matters when materializing an object I only wrote a load_construct_data function.
The example in the documentation does show both a save_construct_data and a load_construct_data function and if I uncomment save_construct_data in the code below, it runs without error and reconstructs the object.
HOWEVER, this only works because the data are written out twice, and then read in twice. I think the problem is that
TestBed.exe!boost::archive::detail::pointer_iserializerboost::archive::text_iarchive,A::load_object_ptr(boost::archive::detail::basic_iarchive & ar, void * t, const unsigned int file_version) Line 340
at J:\Programs\boost_1_76_0\boost\archive\detail\iserializer.hpp(340)
first materializes the object and then--after it is already constructed--passes it off to
ar_impl >> boost::serialization::make_nvp(NULL, * static_cast