When
1) trying to restore from archive the pointer to sample class, and
2) archive is over at this moment
boost::serialization causes Access Violation Fault in
file: basic_iarchive.cpp, line 470:
bpis_ptr = co.bpis_ptr;
The code to reproduce the fault follows.
--
Konstantin Andreev.
------------------------( cut here )----------------------
#include <iostream>
#include <sstream>
#include
#include
class Sample
{
private:
int pod_int;
std::string pod_str;
template<class Archive>
void serialize(Archive & ar, const unsigned int ){
ar & pod_int & pod_str;
};
friend class boost::serialization::access;
friend std::ostream & operator<<(std::ostream & os, const Sample & sa );
public:
Sample() {};
Sample( int _i, std::string _s ) : pod_int( _i), pod_str( _s ) {};
};
BOOST_CLASS_TRACKING(Sample, track_never)
BOOST_CLASS_VERSION(Sample, 19)
std::ostream & operator<<(std::ostream & os, const Sample & sa )
{
return os << "-- int: " << sa.pod_int << ", str: >" << sa.pod_str
<< "< at 0x " << &sa << '\n';
}
int main( void )
{
Sample *obj_to = NULL;
const Sample * const obj_fr = new Sample( 55, "**** test string *****" );
std::cout << *obj_fr;
std::stringstream archbuf;
boost::archive::text_oarchive *oa = new boost::archive::text_oarchive( archbuf, 3 );
*oa << obj_fr;
std::cout << "-- archive content: >" << archbuf.str() << "<\n";
delete oa;
boost::archive::text_iarchive *ia = new boost::archive::text_iarchive( archbuf, 3 );
*ia >> obj_to;
std::cout << *obj_to;
///////////////////////////////////
*ia >> obj_to; // ARCHIVE IS OVER. BOOM !!!
///////////////////////////////////
std::cout << *obj_to;
delete ia;
return 0;
}