Cereal 找不到任何输出序列化函数

Cereal could not find any Output serialization functions

我不知道为什么在尝试编译时会出现此错误。我尝试添加几乎所有类型。我正在尝试序列化一组 RegDoneEntry 的 .我知道序列化的调用不在这里,但我不能超越这个。以下内容已更新以反映建议。

我现在得到的错误是

Severity Code Description Project File Line Suppression State Error LNK2001 unresolved external symbol "public: static class std::set,class std::allocator > RegDoneList::mylist" (?mylist@RegDoneList@@2V?$set@VRegDoneEntry@@U?$less@VRegDoneEntry@@@std@@V?$allocator@VRegDoneEntry@@@3@@std@@A) CerealTest CerealTest.obj 1

#include "stdafx.h"
#include "cereal/archives/binary.hpp"
#include "cereal/types/set.hpp"
#include <sstream>
#include <iostream>
#include <fstream>
#include <string>
#include <set>
#include <stdio.h>
#include "test.h"

RegDoneList myRegDoneList;

int main()
{
    myRegDoneList = RegDoneList();

    myRegDoneList.mylist = std::set<RegDoneEntry>();
    std::ofstream ss("c:\reg.bin", std::ofstream::binary | 
        std::ofstream::out | std::ofstream::trunc);

    cereal::BinaryOutputArchive oarchive(ss);
    oarchive(myRegDoneList); // Write the data to the archive

}

bool operator<(const RegDoneEntry& lhs, const RegDoneEntry& rhs)
{
    return lhs.rawData < rhs.rawData;
}

和头文件:

#include "stdafx.h"
#include "cereal/archives/binary.hpp"
#include "cereal/types/memory.hpp"
#include <sstream>
#include <iostream>
#include <fstream>
#include <string>
#include <set>
#include <stdio.h>


class RegDoneEntry
{
public:
    std::string rawData;
    int operation;
    template<class Archive>
    void serialize(Archive & archive)
    {
        // serialize things by passing them to the archive
        archive(rawData, operation);
    }
    friend bool operator< (const RegDoneEntry &left, const RegDoneEntry &right);

};


class RegDoneList
{
public:
    static std::set<RegDoneEntry> mylist;
    template<class Archive>
    void serialize(Archive & archive)
    {
        // serialize things by passing them to the archive
        archive(mylist);
    }
};

Class RegDoneEntry 也应该定义 serialize 方法。

struct RegDoneEntry
{
  std::string rawData;
  int operation;

  template<class Archive>
  void serialize (Archive& ) {  //... 
  } 
};

接下来,您想要创建一组 RegDoneEntry 对象,但是如果没有 operator< RegDoneEntry class,您的代码将不会被编译。 您还应该在 RegDoneEntry

的定义中添加此运算符
struct RegDoneEntry {
   // ...code from above
   bool operator < (const RegDoneEntry& ) const {
       // your comparison
   }
};

最后一件事,你已经设置为静态成员,但你没有在源代码中定义它,所以你也应该添加这一行

std::set<RegDoneEntry> RegDoneList::mylist;