cereal
A C++11 library for serialization
Public Member Functions | Public Attributes | List of all members
cereal::base_class< Base > Struct Template Reference

Casts a derived class to its non-virtual base class in a way that safely supports abstract classes. More...

#include </build/libcereal-SAfJB3/libcereal-1.3.2+dfsg/include/cereal/types/base_class.hpp>

Inheritance diagram for cereal::base_class< Base >:
cereal::traits::detail::BaseCastBase

Public Member Functions

template<class Derived >
 base_class (Derived const *derived)
 

Public Attributes

Base * base_ptr
 

Detailed Description

template<class Base>
struct cereal::base_class< Base >

Casts a derived class to its non-virtual base class in a way that safely supports abstract classes.

This should be used in cases when a derived type needs to serialize its base type. This is better than directly using static_cast, as it allows for serialization of pure virtual (abstract) base classes.

This also automatically registers polymorphic relation between the base and derived class, assuming they are indeed polymorphic. Note this is not the same as polymorphic type registration. For more information see the documentation on polymorphism. If using a polymorphic class, be sure to include support for polymorphism (cereal/types/polymorphic.hpp).

See also
virtual_base_class
struct MyBase
{
int x;
virtual void foo() = 0;
template <class Archive>
void serialize( Archive & ar )
{
ar( x );
}
};
struct MyDerived : public MyBase //<-- Note non-virtual inheritance
{
int y;
virtual void foo() {};
template <class Archive>
void serialize( Archive & ar )
{
ar( y );
}
};
void serialize(Archive &, std::less< T > &)
Saving for std::less.
Definition: functional.hpp:39
Casts a derived class to its non-virtual base class in a way that safely supports abstract classes.
Definition: base_class.hpp:101

The documentation for this struct was generated from the following file: