You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include <cereal/archives/binary.hpp>
#include <fstream>
#include <iostream>
#include <memory>
#include <string>
struct MyStruct {
int intValue;
// Serialization method using smart pointers
template <class Archive>
void serialize(Archive& archive) {
archive(intValue);
}
};
int main() {
// Create an instance of MyStruct using std::shared_ptr
std::shared_ptr<MyStruct> myStruct = std::make_shared<MyStruct>();
myStruct->intValue = 42;
// Serialize the std::shared_ptr to a binary file
{
std::ofstream ofs("data.bin", std::ios::binary);
cereal::BinaryOutputArchive archive(ofs);
archive(myStruct);
}
return 0;
}
Compilation error:
cereal::OutputArchive<ArchiveType, Flags>::operator()(Types&& ...) [with Types = {std::shared_ptr&}; ArchiveType = cereal::BinaryOutputArchive; unsigned int Flags = 1]’
[build] ../08-serialization/src/serialization_smart_ptr.cpp:31:21: required from here
[build] ../external/cereal/include/cereal/cereal.hpp:570:87: error: static assertion failed: cereal could not find any output serialization functions for the provided type and archive combination.
This works on modify
std::shared_ptr myStruct = std::make_shared();
myStruct->intValue = 42;
to
MyStruct myStruct;
myStruct.intValue = 42.
Any suggestions on what I am missing?
Thanks
The text was updated successfully, but these errors were encountered:
Minimal code:
Compilation error:
cereal::OutputArchive<ArchiveType, Flags>::operator()(Types&& ...) [with Types = {std::shared_ptr&}; ArchiveType = cereal::BinaryOutputArchive; unsigned int Flags = 1]’
[build] ../08-serialization/src/serialization_smart_ptr.cpp:31:21: required from here
[build] ../external/cereal/include/cereal/cereal.hpp:570:87: error: static assertion failed: cereal could not find any output serialization functions for the provided type and archive combination.
This works on modify
std::shared_ptr myStruct = std::make_shared();
myStruct->intValue = 42;
to
MyStruct myStruct;
myStruct.intValue = 42.
Any suggestions on what I am missing?
Thanks
The text was updated successfully, but these errors were encountered: