有人可以帮我这个简单类的序列在C++:如何序列化这个类?
class State {
public:
int count;
Point point;
double angle;
Point* possible;
int possibleSize;
Line line;
list<Point> route;
State() {
}
~State() {
delete[] possible;
}
};
// --- Structures
// Line structure (ax + by + c = 0)
struct Line {
int a;
int b;
int c;
};
// Point structure
struct Point {
int x;
int y;
};
我不能使用任何第三方类或库,我需要序列化到字节数组(或字符串)这一点。有人可以写如何?我只是不知道如何开始。
非常感谢。
你的类是越野车:它会调用未定义的行为,当因为可能'复制或分配时,考虑使用'std :: vector'而不是裸数组。 –
2010-11-16 15:18:50