谷物序列化错误

编程入门 行业动态 更新时间:2024-10-27 20:39:21
本文介绍了谷物序列化错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以我很困惑.它不会为外部序列化功能进行编译.它给出了错误

So i'm legit confused. It won't compile for an external serialization function. It gives the error

谷物无法找到任何输出序列化函数 提供的类型和归档组合.

cereal could not find any output serialization functions for the provided type and archive combination.

因此下面的代码无法编译

So the code below doesn't compile

#include <fstream> #include <glm/glm.hpp> #include "SceneObject.h" #include <cereal/cereal.hpp> #include <cereal/archives/json.hpp> template<typename Archive> void serialize(Archive& archive, glm::vec3& v3) { archive(cereal::make_nvp("x", v3.x), cereal::make_nvp("y", v3.y), cereal::make_nvp("z", v3.z)); } struct something { public: float x, y, z; }; template<typename Archive> void serialize(Archive& archive, something& v3) { archive(cereal::make_nvp("x", v3.x), cereal::make_nvp("y", v3.y), cereal::make_nvp("z", v3.z)); } int main(int argc, char** argv) { SceneObject test; test.transform().setPosition(1.0f,2.0f,3.0f); { std::ofstream file("TestPath.json"); cereal::JSONOutputArchive output(file); glm::vec3 p = test.transform().getPosition(); output(p); } return 0; }

但这确实可以编译

#include <fstream> #include <glm/glm.hpp> #include "SceneObject.h" #include <cereal/cereal.hpp> #include <cereal/archives/json.hpp> template<typename Archive> void serialize(Archive& archive, glm::vec3& v3) { archive(cereal::make_nvp("x", v3.x), cereal::make_nvp("y", v3.y), cereal::make_nvp("z", v3.z)); } struct something { public: float x, y, z; }; template<typename Archive> void serialize(Archive& archive, something& v3) { archive(cereal::make_nvp("x", v3.x), cereal::make_nvp("y", v3.y), cereal::make_nvp("z", v3.z)); } int main(int argc, char** argv) { SceneObject test; test.transform().setPosition(1.0f,2.0f,3.0f); { std::ofstream file("TestPath.json"); cereal::JSONOutputArchive output(file); glm::vec3 p = test.transform().getPosition(); something s; s.x = p.x; s.y = p.y; s.z = p.z; output(s); } return 0; }

我从字面上将保存代码从glm :: vec3复制并粘贴到某些东西,然后将glm :: vec3更改为'something'.对我而言,它为什么对一个而不对另一个有用,这没有任何意义.我认为这可能是名称空间的事情,但是我不知道如何解决该问题.

I literally copy and pasted the save code from glm::vec3 to something and just changed glm::vec3 to 'something'. It makes NO sense to me why it would work for one and not the other. I think it might be a namespace thing, but I have no clue how to fix that.

推荐答案

显然,发布使我找到了解决方案.

Well apparently posting made me find the solution.

您需要确保序列化函数共享相同的名称空间,因此如果我像

You need to make sure the serialize functions share the same namespace so if I wrap them like

namespace glm { template<typename Archive> void serialize(Archive& archive, glm::vec3& v3) { archive(cereal::make_nvp("x", v3.x), cereal::make_nvp("y", v3.y), cereal::make_nvp("z", v3.z)); } }

有效.有点奇怪,但这就是事实.

It works. Kinda odd, but it is what it is.

更多推荐

谷物序列化错误

本文发布于:2023-10-25 14:34:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1527235.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:谷物   错误   序列化

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!