序列化/反序列化没有序列化成员的现有类

时间:2015-05-04 21:45:09

标签: c++ serialization boost

我试图序列化NTL::ZZ_p类,以便我可以通过网络发送它。为了完整性 - 该类没有序列化方法:

class ZZ_p {
public:

   ZZ_p(); // initialize to 0

   ZZ_p(const ZZ_p& a); // copy constructor
   explicit ZZ_p(long a);  // promotion constructor

   ~ZZ_p(); // destructor

   ZZ_p& operator=(const ZZ_p& a); // assignment
   ZZ_p& operator=(long a); // assignment

   static void init(const ZZ& p);
   // ZZ_p::init(p) sets the modulus to p (p > 1)

   static const ZZ& modulus();
   // ZZ_p::modulus() yields read-only reference to the current
   // modulus

   // typedefs to aid in generic programming
   typedef ZZ rep_type;
   typedef ZZ_pContext context_type;
   typedef ZZ_pBak bak_type;
   typedef ZZ_pPush push_type;
   typedef ZZ_pX poly_type;
};

但在同一个文件中有两个功能:

ostream& operator<<(ostream& s, const ZZ_p& a);
istream& operator>>(istream& s, ZZ_p& x);

一般来说我想用boost来序列化它,但是ostream / istream也没关系。

你能告诉我如何序列化吗?

到目前为止,我在课堂上做过(id是整数,k0,k1NTL::ZZ_p):

friend class boost::serialization::access;

  template<typename Archive>
  void serialize(Archive& ar, const unsigned version) {
    ar & id;
    ar << k0;
    ar << k1;  // Simply serialize the data members of MyObj
  }

并发送给我:

PreProcess1 pp1(iter->first, iter2->second[0], iter2->second[1]);
std::string msg;
std::stringstream ss;
boost::archive::text_oarchive ar(ss);
int msg_type = PRE_PROCESS_1;
ar & msg_type & pp1;
msg = ss.str();
mComm->Send(iter2->first, msg.c_str(), msg.size());

我收到了错误:

/usr/include/boost/serialization/access.hpp:118:9: error: ‘class NTL::ZZ_p’ has no member named ‘serialize’

0 个答案:

没有答案