S
shuisheng
Dear All,
Assume I have two classes: material and shape, as follows
class Material
{
double density; // material attribute, may have more
vector<Shape*> pShape; // shape objects assocaited the material.
};
class Shape
{
double size; // shape attribute, may have more
vector<Material*> pMaterial; // material objects associated with the
shape
};
and I have two objects:
vector<Material*> pMaterial;
vector<Shape*> pShape;
And I want to save the two objects into a file and then open it by
using fstream. But here pointer is used to represent the association
relation. If I simply save the pointer address in to the file, when
opening there is no gurantee to have those materials and shapes at the
same address. Is there any good way to solve the problem?
Thanks,
Shuisheng
Assume I have two classes: material and shape, as follows
class Material
{
double density; // material attribute, may have more
vector<Shape*> pShape; // shape objects assocaited the material.
};
class Shape
{
double size; // shape attribute, may have more
vector<Material*> pMaterial; // material objects associated with the
shape
};
and I have two objects:
vector<Material*> pMaterial;
vector<Shape*> pShape;
And I want to save the two objects into a file and then open it by
using fstream. But here pointer is used to represent the association
relation. If I simply save the pointer address in to the file, when
opening there is no gurantee to have those materials and shapes at the
same address. Is there any good way to solve the problem?
Thanks,
Shuisheng