下面是Boost serialization 中的demo例子
为何写了serialize 函数还写个ostream<<
阿,
我对ostream 不是很了解,
我的印象是iostream 是在控制台里输入输出的
/////////////////////////////////////////////////////////////////////////////
class gps_position
{
friend std::ostream & operator<<(std::ostream &os, const gps_position &gp);
friend class boost::serialization::access;
int degrees;
int minutes;
float seconds;
template<class Archive>
void serialize(Archive & ar, const unsigned int /* file_version */){
ar & degrees & minutes & seconds;
}
public:
// every serializable class needs a constructor
gps_position(){};
gps_position(int _d, int _m, float _s) :
degrees(_d), minutes(_m), seconds(_s)
{}
};
std::ostream & operator<<(std::ostream &os, const gps_position &gp)
{
return os << ' ' << gp.degrees << (unsigned char)186 << gp.minutes << '\'' << gp.seconds << '"';
}