Iterating a struct in C++ -
i'm having trouble iterating on struct.
the struct can defined differently, depending on compiler flags. want set struct members 0. don't know how many members there are, guaranteed numbers (int, long...)
see example below:
#ifdef flag1 struct str{ int i1; long l1; doulbe d1; }; #elsif defined (option2) struct str{ double d1 long l1; }; #else struct str{ int i1; }; #endif
i guess pseudo-code want is:
void f (str * tozero) { foreach member m in tozero m=0 }
is there way in c++?
to initialise podo's data 0 in c++ use = { 0 }
. don't need iterate on every member.
structfoo* instance = ... *instance = { 0 };
Comments
Post a Comment