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

Popular posts from this blog

javascript - IndexedDB error: Uncaught DataCloneError: Failed to execute 'put' on 'IDBObjectStore': An object could not be cloned -

amazon web services - When using Cognito credentials with AWS in a browser (javascript), keep getting "missing credentials" error -

c# - How to set the datatextfield value instead of the value on a drop down list? -