-1

我试图在我的类中获取两个数组以使用 boost 序列化库。我可以很好地保存数据,但由于某种原因,我无法将其加载回来。我认为它与 ia >> *this; 但我不知道如何解决它。任何人都可以指出我正确的轨道吗?

class foo
{

private:
int tileType[512];
int tileSubType[512];

friend std::ostream & operator<<(std::ostream &os, const foo &gp);
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
    ar & tileType;
    ar & tileSubType;
}

public:
foo();

void loadType(string data)
{
    std::stringstream is(data);

    boost::archive::text_iarchive ia(is);
    ia >> *this;
}

string saveType()
{
    stringstream ss(stringstream::in | stringstream::out);
    boost::archive::text_oarchive oa(ss); 
    oa << this;

    return ss.str().c_str();
}

};
4

2 回答 2

1

你有没有尝试过

 oa << *this;

?

您正在保存指针但加载到引用中,我想这不是您想要的,对吧?

于 2011-07-12T15:22:45.197 回答
0

我在尝试将>>and<<运算符与档案一起使用时遇到了一些问题。尝试在&这两种情况下使用运算符,看看是否可以为您解决问题。

于 2011-07-12T15:27:34.200 回答