cereal
cereal copied to clipboard
Static Assert - false positives
This is my class, which I wrote - also referencing the quick-start section of the docs of cereal
Scene.h
namespace Sentinel {
struct Scene {
public:
Scene();
Scene(const STL::string& name);
~Scene();
public:
template<class Archive>
void save(Archive& archive) const {
archive(cereal::make_nvp("SceneName", m_UUID.ToString().c_str()));
}
template<class Archive>
void load(Archive& archive) {
archive(cereal::make_nvp("SceneName", m_UUID.ToString().c_str()));
}
private:
UUID m_UUID {};
private:
friend cereal::access;
};
} // namespace Sentinel
As you can see, it is as straightforward as it can get.
However, whenever I try to put a serialization function in the Scene
class itself, and try to serialize it, like this:
void Scene::SerializeScene(const std::string& path) {
std::ofstream stream(path.c_str());
cereal::JSONOutputArchive archive(stream);
archive(*this);
}
It throws an error - static_assert failed: 'Cereal does not support serializing raw pointers - please use a smart pointer'
When I try to pass the class to an external manager class, like this:
void SceneManager::SaveToFile(const std::string& filePath, std::shared_ptr<Scene> scene) {
std::ofstream stream(filePath.c_str());
cereal::JSONOutputArchive archive(stream);
archive(scene);
}
It throws an error - static_assert failed: 'cereal could not find any output serialization functions for the provided type and archive combination.
Both of these static asserts are inexplicable and not able to convey exactly where is the issue happening. Can anyone please help me, or take a look at this?