我是序列化的新手,我在使用Cereal librarystd::vector
序列化对象时遇到了麻烦。这是一个说明问题的示例:
class MyClass
{
int x, y, z;
class MyOtherClass
{
string name, description;
public:
template<class Archive>
void serialize(Archive & archive)
{
archive(name, description);
}
};
vector<MyOtherClass> Victor;
vector<int> ints;
public:
template<class Archive>
void serialize(Archive & archive)
{
archive(x, y, z, ints); // error C2338: cereal could not find any output serialization functions for the provided type and archive combination.
}
};
尝试序列化ints
对象或Victor
对象会导致error C2338: cereal could not find any output serialization functions for the provided type and archive combination.
这是我在main
函数中使用的代码:
MyClass MyObject;
ofstream datafile(path, ios::binary);
{ cereal::BinaryOutputArchive oarchive(datafile); oarchive(MyObject); }
我究竟做错了什么?