Reputation: 193
Ciao folks,
I'm quiet desperate not to find the source of the problem. I'm using Boost:serialization (version 1.46.1) and everything was working fine with binary_oarchive
. I have a hierarchy of classes and, thus, I use the register_type()
.
However, where I came to use binary_iarchive
to unserialize my objects, I got
error: cannot allocate an object of abstract type
which comes from the call of register_type()
on the input archive.
After googling I found out that the macro BOOST_SERIALIZATION_ASSUME_ABSTRACT(T)
must be used for the abstract classes. The problem is that it simply doesn't work :).
Can anyone help me out ?
More about my code :
virtual void AbstractClass::initBinarySerialization(binary_iarchive& ia)
{
ia.register_type<AbstractClass>();
}
virtual void SubClass::initBinarySerialization(binary_iarchive& ia)
{
AbstractClass::initBinarySerialization(ia);
ia.register_type<SubClass>();
}
I call initBinarySerialization
before reading in the archive.
Upvotes: 1
Views: 1039
Reputation: 361692
error: cannot allocate an object of abstract type
It seems somewhere in your code, you're creating instance(s) of an abstract class. That is why you're getting this error, because creating instance of abstract class is forbidden. You can create instance(s) of only concrete classes.
You need to tell boost that X is an abstract class, by writing:
BOOST_SERIALIZATION_ASSUME_ABSTRACT(X);
Now follow this topic which explains it further:
Upvotes: 1