所以我很困惑。它不会为外部序列化函数编译。它给出了错误
谷物找不到提供的类型和存档组合的任何输出序列化函数。
所以下面的代码不能编译
#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 更改为“某物”。这对我来说毫无意义,为什么它适用于一个而不是另一个。我认为这可能是一个命名空间的事情,但我不知道如何解决这个问题。