$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: __PPS__ (i-love-spam_at_[hidden])
Date: 2005-12-06 04:04:15
__PPS__ wrote:
> 
> Yes, there's no need to include <boost/serialization/serialization.hpp>, 
> it could be removed from the export.h, but it doesn't mean that my DLL 
> code doesn't include archives' code. Inside implementation of this 
> (de)serialize functions (somewhere inside export.cpp, or whatever) I 
> include all the archives code etc.
> 
> basicly, here's export.cpp
> /////
> //all needed includes & using namespace ...
> 
> #include "export.h"
> session_record::~session_record(){}
> session_record::operator session_record *(){
> 	return this;
> }
> 
> void serialize(session_record* derived, const char* file_name){
> 	ofstream out(file_name);
> 	if(!out || !out.is_open()) throw std::runtime_error(std::string("failed 
> to open \"")+file_name+'"');
> 	text_oarchive oa(out, no_header | no_codecvt);
> 	oa & derived;
> }
> session_record* deserialize(const char* file_name){
> 	ifstream in(file_name);
> 	text_iarchive ia(in, no_header | no_codecvt);
> 	session_record *derived;
> 	ia & derived;
> 	return derived;
> }
> /////////
> 
> 
> 
> 
> then in another app, that links to export.dll I have:
> /// needed includes & using declarations ...
> #include "export.h"
> 
> class client_record : public virtual session_record {
>    friend class boost::serialization::access;
>    template<class Archive> void serialize(needed args...){
>      serialization::base_object<session_record>(*this);
>      ar & name;
>      ar & address;
>      ar & amount;
>    }
>    virtual void print_on(std::ostream &os)const{
>      os <<
>      "client record: \n"
>      "\tname: " << name << "\n"; //....
>    }
> public:
>    std::string name, address;
>    double amount;
> };
> BOOST_CLASS_EXPORT(client_record);
> 
> main()try{
> 
>    client_record x;
>    x.name = "John Doe";
>    x.amount = 129.99;
>    x.address = "2080 Wellington, apt. 13";
>    serialize(&x, "xxx.txt");
> 
> }catch (const exception &e) {
>    cout << "error: " << e.what() << endl;
> }
> 
> /////////
> 
> I get unregistered class exception. I use vc71 and if I now in settings 
> for the export.dll change project type from Dll to static library, and 
> recompile my test program, everything works as expected.
> and this error I get is from serializing from base pointer, not from 
> deserializing...
> 
one other thing...
inside section "Runtime casting" there's 2nd method for registering 
derived class:
boost::serialization::void_cast_register<derived, base>();
it seems that it was changed or something, but it doesn't work for me.
vc ide shows that this function expects 2 arguments. I also tried to 
call it this way:
boost::serialization::void_cast_register<derived, base>(this,this);
but it also didn't seem to work
i use boost 1.33.0