I'm not sure why you're doing that? If you didn't add anything to var1.fooVec, the size of the vector will be 0.
Yep, isn't my intention to set all vector elements to Zero, but rather initialize an entire struct that contains an STL dynamic array without adding a function to my struct.
Ex:
Code:
struct foo{
int a;
float b;
double c;
vector<int> d;
};
foo var1;
ZeroMemory(&var1, sizeof(foo));
So think the following would be safe?
Code:
ZeroMemory(&var1, sizeof(foo) - sizeof(vector<int>)); //Assuming of course my vector is at the end of the struct.
I'm assuming the sizeof() a class never changes... and yep I should probably stop being lazy and just write a constructor... but I'm afraid I will want to down the road do a binary dump of my struct to a file and I'm looking for more "data storage" struct rather than a full class with Read() & Write() members, etc.
Code:
file.Write(&var1, sizeof(foo) - sizeof(vector<int>));
file.Write(&var1.d[0], var1.d.size() * sizeof(int));
Thanks for any input.
edit: Ah I remember why I was posting this question... quickly initializing embedded structs.
Example:
Code:
struct one{
int a;
int b;
float c;
double d;
BYTE *data;
two innerStruct;
};
struct two{
int a;
int b;
int c;
int d;
vector<int> e; <--- using STL vector to not have to worry about mem. management.
};
one outerStruct;
ZeroMemory(&one, sizeof(outerStruct));
Guess there is no easy way to do this without either.
a) Writing constructor for both structs.
b) Initializing of all veriables at each declaration.
c) Replacing all STL classes with simple pointers.
d) Possibly if careful enough ZeroMemory(&one, sizeof(outerStruct) - sizeof(vector<int>), which would really hinder growth.