如何在c ++中循环一个类的公共变量?(How to loop over the public variables of a class in c++? [duplicate])
这个问题在这里已经有了答案:
有没有办法在c ++中将函数应用于结构的每个成员? 13个答案 我可以遍历C ++类的(公共)属性吗? 2个答案如何循环(在c ++中预测类的公共变量),我有如下的temp_class
class temp_class { public: std::string name; int age; class2 object_class; private: //some code here }现在我需要获取类中所有公共变量的列表(如果我们想获得ac#类的所有属性的列表,那么有些类似的东西,但对于c ++类)
temp_class object_class; //here these is a code to set the values for each public variable in the object foreach(public_variable in object_class) { string var_name=//get the public variable name string var_value=//get the public variable value }This question already has an answer here:
Is there a way of applying a function to each member of a struct in c++? 13 answers Can I loop through (public) attributes of a C++ class? 2 answersHow to loop (foreach public variable of class in c++), I have temp_class like the following
class temp_class { public: std::string name; int age; class2 object_class; private: //some code here }Now I need to get a list of all public variable in the class (some thing similar if we want to get a list of all the properties of a c# class, but for c++ class)
temp_class object_class; //here these is a code to set the values for each public variable in the object foreach(public_variable in object_class) { string var_name=//get the public variable name string var_value=//get the public variable value }最满意答案
你不能。 这是C ++,没有真正反射的非托管代码。
You can't. this is C++ , unmanaged code without true reflection.
更多推荐
发布评论