views:

56

answers:

2

Possible Duplicate:
Iterate through struct variables.

So I have a header file and a code file. The class is representation of a View that will be queried from stored proc. For each col. in view there is one data member in class. Currently in code we have something like this:

Load( Reader reader)
{
   m_col1 = reader("m_col1");
   m_col2 = reader("m_col2");
   ..
}

How can I write a code that will iterate through member variables and give me code like:

Load( Reader reader)
{
   For (each str in ArrayOfMemberVariables)
     variableLValue(str) = reader(str); //  str = m_col1,  m_col2  ...
}
A: 

The C++ reflection question has been brought up several times. Unfortunately, it's not possible unless you manage the metadata yourself. See this question for more details.

codelark
A: 

If you mean declaring variables names dynamicly like in PHP for example (using other variable names), you can't do that in C++.

In C++ you don't have the notion of reflection like in Java where you can introspect the variables of your class and code around that to do things like serialization with knowing in advance the class members.

David