USCiLab/cereal

Cereal polymorphism not working in base class

Opened this issue · 0 comments

Hello,
I have this project with a polymorphism in it.
The structure of the project:
I have a BaseClass which is the parent class in BaseDll (DLL) , and I have DerviedClass which inhereted from BaseClass and it's in DerivedProject (console application) in the same solution. The scenario is serializing DerviedClass in BaseClass and not the opposite, and when I am trying to serialize DerivedProject in BaseDll this error appear

Trying to save an unregistered polymorphic type (class child).
Make sure your type is registered with CEREAL_REGISTER_TYPE and that the archive you are using was included
(and registered with CEREAL_REGISTER_ARCHIVE) prior to calling CEREAL_REGISTER_TYPE.
If your type is already registered and you still see this error, you may need to use CEREAL_REGISTER_DYNAMIC_INIT.

I used CEREAL_REGISTER_POLYMORPHIC_RELATION and it didn't work, then i tried to use CEREAL_FORCE_DYNAMIC_INIT , CEREAL_REGISTER_DYNAMIC_INIT and it also didn't work.

When I tried to include the subclass into base class header (which is a wrong concept) it worked!! However, I do not prefer to do this. So, I removed the include header and tried to use forward declration, but it did not work.
Please, kindly find the project attached to this post to advice me what to do.
Note: You can find the commented include header which when you uncomment "and that is wrong as I mentioned" everything works fine.
Thanks in advance.

cerealPolymorphism.zip