I split my test program up from 1 .cpp file into proper headers and implementation files.... (we'll fight the fight with dlls next)
I now get a unregisted_class exception when I do this: (MSVC 11.0, windows7, win32 compile)
int main(int argc, char* argv[])
{
const ABase* a = new ABase("I'm cool");
const ABase* c = new C(*a,54.2f);
cout <<*a<<"\n"<<*((C*)c)<<endl;
ofstream ofs("dump.bin");
try
{
boost::archive::text_oarchive oa(ofs);
//boost::archive::binary_oarchive oa(ofs);
oa<<a;
oa<<c; //THIS TRIGGERS THE EXCEPTION
}
catch(boost::archive::archive_exception& ae)
{
cout<<ae.what();
}
Where C inherets from ABase.
C.h:
#ifndef C_HPP
#define C_HPP
#include "A.h"
class C : public ABase
{
friend class boost::serialization::access;
friend std::ostream& operator << (std::ostream&,const C&);
public:
C();
C(const ABase&);
C(const ABase&,float);
virtual ~C();
private:
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & boost::serialization::base_object<ABase>(*this);
ar & m_blah;
}
float m_blah;
};
BOOST_CLASS_EXPORT_KEY( C )
#endif
c.cpp:
#include "C.h"
using namespace std;
BOOST_CLASS_EXPORT_IMPLEMENT( C )
C::C()
{
}
C::C(const ABase&a,float b):
ABase(a),
m_blah(b)
{
}
C::~C()
{
}
ostream& operator << ( ostream& out, const C& rhs)
{
out << dynamic_cast<const ABase&>(rhs)
<<" "
<<rhs.m_blah
<<endl;
return out;
}
I do not for the life of me understand. I am registering the classes like the documentation says....
Larry E. Ramey