开发者

How to get all properties/variables of a class at runtime/dynamically in C++

is this possible to 开发者_如何转开发get all the variables and methods of a class at runtime? if yes then how? I did this in C# using Reflection. but now i am working in C++.


There is no way to do what you are asking in C++. As suggested in the other answer, RTTI can help you, but is probably not what you need.

If you describe in more details what you are trying to do and why you need reflection, we can probably suggest other solutions in C++.


You can use RTTI in C++.

This is just an opinion: It's not as easy/straighforward as C#'s reflection API.

Also check out this SO question.


While you can determine the type of an object using RTTI, C++ is not fully reflective and you cannot take a normal C++ class and determine what methods or variables it has.


I don't think there is a way to enumerate members of a class. A while ago I needed the very same thing, and in the end settled with manual registration of every member and every class of interest in my own container. Even then, members were all of the same basic type (replacement for Object class from C#). Enumerating members and calling the base function of each member is easy then. It works, and I'm happy.


I find this repo. https://github.com/Celtoys/clReflect Create reflection data and load.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜