Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2006-12-12 12:20:49


I've compiled and run your example on my vc 7.1 system and it works fine.
So there's not a lot I can say.

But that won't stop me from offering a couple of suggestions:

Your example looks correct to me - and it compiles and runs well - But I
have a couple of quesions about it.

a) The usage of a function string serialize(...) is not incorrect, but it
could be confusing to a compiler with an issue with overloading. At the
very least it makes the example harder to follow and might make error
messages undecipherable.

b) The following usage of string stream makes me wonder:

string serialize(const base * const b){
stringstream str;
boost::archive::text_oarchive oa(str);
oa << b;
return str.str();
}

The order of destruction is:

return (copy? string)
destroy archive - this might add closing characters to the archive
destroy string stream

So I'm not certain that the string contains all the characters added to the
archive.

So I would try reformlating your example like the following:

...
BOOST_IS_ABSTRACT(base);
BOOST_CLASS_EXPORT(derived);
int main(){
stringstream str;
const base * const d1 = new derived(52,"a string");
{
d1->do_it();
boost::archive::text_oarchive oa(str);
oa << d1;
}
base *d2;
{
boost::archive::text_iarchive ia(str);
ia >> d2;
d2->do_it();
}
return 0;
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net