reflection c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

reflection c++

hi guys.. i would like to know if it is possible to get info like classname, property in c++ during runtime?

24th Apr 2021, 11:16 AM
durian
durian - avatar
1 Answer
+ 1
You could just make a common static property on all your classes which holds the class name. This way you can access the class name using that static property. The omly downside to this is that this solution is only valid for user-defined classes. You could instead use the typeid operator to get information about the type in the form of a std::type_info object, and then use the std::type_info::name() method to get the name of the type. The only problem is that on some compilers, the name returned is the mangled name of the class. It can be demangled using the abi::__cxa_demangle() function of the <cxxabi.h> header (l'm not sure if it is linux specific or not). Example: https://code.sololearn.com/cg138yItBFz4/?ref=app
24th Apr 2021, 1:19 PM
XXX
XXX - avatar