I have a simple classe here :
template <typename T>
class clDaughter
{
public:
T* __pData;
uint16_t __u16Size;
clDaughter() [...]
~clDaughter() [...]
clDaughter(uint16_t const ku16Size)
{
this->__pData = (T*)malloc(ku16Size * sizeof(T));
this->__u16Size = ku16Size;
}
template<class Archive>
void save(Archive & ar) const
{
ar(this->__u16Size);
ar(cereal::binary_data(this->__pData, this->__u16Size * sizeof(T)));
}
template<class Archive>
void load(Archive & ar)
{
uint16_t u16LoadedSize;
ar(u16LoadedSize);
this->__pData = (T*)malloc(u16LoadedSize * sizeof(T));
this->__u16Size = u16LoadedSize;
ar(cereal::binary_data(this->__pData, this->__u16Size * sizeof(T)));
}
};
This is working fine, I mean, serialization in and out is tested ok.
Trouble starts when I want to use polymorphism here. This daughter class inherits from a pure virtual mother class, as well as other "daugter-like" classes.
class clDaugter_A : public clMother
{
[...]
}
class clDaugter_B : public clMother
{
[...]
}
And, when I want to register my clDaughter class using the CEREAL_REGISTER_TYPE(...)
macro,
CEREAL_REGISTER_TYPE(clDaugter_A<int>)
CEREAL_REGISTER_TYPE(clDaugter_B<int>)
compiler crashes with
"cereal could not find any output serialization functions for the provided type and archive combination"
It really seems the problem comes from this binary_data(...)
method because if I serialize the __pData
array in a loop (ugly-style)
for (u16Idx = 0;..;..)
{
ar(this->__pData[u16Idx];
}
I have no error and it works fine. It is only when I use binary_data()
and CEREAL_REGISTER_TYPE()
together.
What did I miss ?
(to pre-empt the question, I do want to use binary_data()
because it's something like 20-30 times faster than the loop and I need to be fast here)
Thank for your help