currently I'm trying to serialize a derived class but when I try to serialize it, only the base serialize is called rather than the derived serialization, so when I try to call load the file, the derived member returns a corrupted number. Is there anyway I can get around to doing this ?
what I'm trying to do is something similar to this
class BASE
{
public:
BASE() {};
int base_mem{};
template <class T>
void serialize(T& t)
{
t(base_mem);
}
}
class DERIVED : public BASE
{
public:
DERIVED() {};
int der_mem{};
template<class T>
void serialize(T& t)
{
t(cereal::base_class<BASE>(this), der_mem);
}
}
void main()
{
std::shared_ptr<BASE>dr = std::make_shared<DERIVED>();
std::ofstream ofs("Output.out", std::ios::binary);
cereal::BinaryOutputArchive out(ofs);
out(dr);
}
I just came across your answer, here is my take on it. If you use plain C++ just remove the Rcpp lines and replace the stream insertion with std::cout.