Hi everyone.I'll just get to the point.I want to write objects of type B to a file in binary form using fstream and it's 'write' member function.I need to pass a size for an object of type B but since it contains dynamic data and i can't use just a plain sizeof(object) should i take the size writing a function like down below ?
class A {
int x;
public:
A (): x(0) {}
~A () {}
};
class B {
std::deque<A*> vec;
public:
B () {}
B (int x) : vec(std::deque<A*>(x,new A()) {}
~B () {
while (vec.size()) {
delete vec[0];
vec.pop_front();
}
int size () {
return vec.size()*sizeof(A)+sizeof(*this); //this is it .. is it ok?
}
};
Thanks a lot