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.
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.
So think the following would be safe?
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.
ZeroMemory(&var1, sizeof(foo) - sizeof(vector<int>)); //Assuming of course my vector is at the end of the struct.
Thanks for any input.
file.Write(&var1, sizeof(foo) - sizeof(vector<int>));
file.Write(&var1.d, var1.d.size() * sizeof(int));
edit: Ah I remember why I was posting this question... quickly initializing embedded structs.
Guess there is no easy way to do this without either.
vector<int> e; <--- using STL vector to not have to worry about mem. management.
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.