cereal icon indicating copy to clipboard operation
cereal copied to clipboard

Can't register polymorhpic type named StaticObject

Open jhasse opened this issue 7 years ago • 3 comments

I'm register a class of mine named StaticObject, but I think this collides because cereal itself has a class named StaticObject.

../subprojects/cereal-1.2.2/include/cereal/details/polymorphic_impl.hpp: In instantiation of ‘const cereal::detail::bind_to_archives<T, Tag>& cereal::detail::bind_to_archives<T, Tag>::bind() const [with T = cereal::detail::StaticObject<Dust>; Tag = cereal::detail::{anonymous}::polymorphic_binding_tag]’:
../src/Dust.hpp:18:1:   required from here
../subprojects/cereal-1.2.2/include/cereal/details/polymorphic_impl.hpp:736:9: error: static assertion failed: Attempting to register non polymorphic type
         static_assert( std::is_polymorphic<T>::value,
         ^~~~~~~~~~~~~

../src/Dust.hpp:18 is this line:

CEREAL_REGISTER_TYPE(StaticObject<Dust>)

StaticObject is a template and definitely polymorphic. If I move it into it's own namespace, everything works.

jhasse avatar Apr 23 '18 09:04 jhasse

Can you show the full class definition for Dust? This might be a name collision or it might be something as simple as not having a virtual function.

AzothAmmo avatar May 08 '18 05:05 AzothAmmo

Dust isn't the class I'm trying to register, but StaticObject (which happens to be a template). Here's a minimal example to reproduce the error:

struct StaticObject
{
  virtual ~StaticObject() = default;
};

CEREAL_REGISTER_TYPE(StaticObject)

jhasse avatar May 08 '18 08:05 jhasse

Another good workaround is using CEREAL_REGISTER_TYPE_WITH_NAME(::StaticObject, "StaticObject").

jhasse avatar Oct 02 '23 10:10 jhasse