开发者

C++, unmanaged, class, members: How (if at all) can I list all the members in a class? [duplicate]

This question already has answers here: Closed 12 years ago.

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 Ar开发者_StackOverflowrayOfMemberVariables)
     variableLValue(str) = reader(str); //  str = m_col1,  m_col2  ...
}


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜