如何在c ++中循环一个类的公共变量?(How to loop over the public variables of a class in c++? [duplicate])

编程入门 行业动态 更新时间:2024-10-18 18:15:49
如何在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 answers

How 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.

更多推荐

本文发布于:2023-08-04 06:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1410125.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   如何在   loop   public   class

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!