cereal::base\_class&lt; Base &gt;(3) Library Functions Manual cereal::base\_class&lt; Base &gt;(3)

# [NAME](#NAME)

cereal::base\_class&lt; Base &gt; - Casts a derived class to its non-virtual base class in a way that safely supports abstract classes.

# [SYNOPSIS](#SYNOPSIS)

#include &lt;/home/build/include/cereal/types/base\_class.hpp&gt;

Inherits **cereal::traits::detail::BaseCastBase**.

## [Public Member Functions](#Public_Member_Functions)

template&lt;class Derived&gt; **base\_class** (Derived const \*derived)

## [Public Attributes](#Public_Attributes)

Base * **base\_ptr**

# [Detailed Description](#Detailed_Description)

## [template&lt;class Base&gt;](#template_class_Base_)

struct cereal::base\_class&lt; Base &gt;"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( cereal::base_class<MyBase>(this) );


    ar( y );


  }
};
```

# [Author](#Author)

Generated automatically by Doxygen for cereal from the source code.

Sat Aug 29 2026 00:42:30 cereal

---

Document: cereal_base_class(3) from cereal 1.3.2-r5 (Chainguard OS)
Source: https://github.com/USCiLab/cereal
