.TH "cereal::base_class< Base >" 3 "Mon Oct 26 2026 20:39:03" "cereal" \" -*- nroff -*- .ad l .nh .SH NAME cereal::base_class< Base > \- Casts a derived class to its non-virtual base class in a way that safely supports abstract classes\&. .SH SYNOPSIS .br .PP .PP \fR#include \fP .PP Inherits \fBcereal::traits::detail::BaseCastBase\fP\&. .SS "Public Member Functions" .in +1c .ti -1c .RI "template \fBbase_class\fP (Derived const *derived)" .br .in -1c .SS "Public Attributes" .in +1c .ti -1c .RI "Base * \fBbase_ptr\fP" .br .in -1c .SH "Detailed Description" .PP .SS "template .br 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\&. .PP 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 (\fBcereal/types/polymorphic\&.hpp\fP)\&. .PP \fBSee also\fP .RS 4 \fBvirtual_base_class\fP .RE .PP .PP .nf struct MyBase { int x; virtual void foo() = 0; template void serialize( Archive & ar ) { ar( x ); } }; struct MyDerived : public MyBase //<\-\- Note non\-virtual inheritance { int y; virtual void foo() {}; template void serialize( Archive & ar ) { ar( cereal::base_class(this) ); ar( y ); } }; .fi .PP .SH "Author" .PP Generated automatically by Doxygen for cereal from the source code\&.