我有一个这样的课:
struct SomeClass{
SomeClass(){}
SomeClass(const SomeClass& rhs):
_m1(rhs._m1),
_m2(rhs._m2),
_m3(rhs._m3),
_m4(rhs._m4){}
SomeClass& operator=(const SomeClass& rhs){
// same as above
return *this;
}
int _m1;
std::vector<int> _m2;
std::vector<int> _m3;
int _m4;
};
Run Code Online (Sandbox Code Playgroud)
在我的程序中的某个时刻,我想保存存储在SomeClass
对象中的数据供以后使用:
SomeClass someObj = arr->getBest(); // arr is a pointer to AnotherClass,
// in which different SomeClass
// objects are initialized and then
// involved in various
// computations in AnotherClass,
// finally the best one SomeClass
// object will be save here
fwrite(&someObj, sizeof(SomeClass), 1, saveFile); …
Run Code Online (Sandbox Code Playgroud)