C++,非托管,类,成员:如何(如果有的话)列出类中的所有成员?
可能的重复:
迭代结构变量。
所以我有一个头文件和一个代码文件。该类是将从存储过程中查询的视图的表示。对于每个列。鉴于类中有一个数据成员。 目前在代码中我们有这样的东西:
Load( Reader reader)
{
m_col1 = reader("m_col1");
m_col2 = reader("m_col2");
..
}
我怎样才能编写一个代码来迭代成员变量并给我这样的代码:
Load( Reader reader)
{
For (each str in ArrayOfMemberVariables)
variableLValue(str) = reader(str); // str = m_col1, m_col2 ...
}
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 ...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

C++反射问题已经被提出过好几次了。不幸的是,除非您自己管理元数据,否则这是不可能的。有关更多详细信息,请参阅此问题。
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.