下面是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 << '"';
}