For example, I have a structure that looks something like this:
struct Test { int i; float f; char ch[10]; };
And I have an object of this structure, for example:
Test obj;
Now I want to programmatically get the field names and type obj. Is it possible?
obj
This is C ++ BTW.
You are requesting Reflection in C ++ .
I am afraid that you cannot get the field names, but you can get the obj type using Boost.Typeof :
#include <boost/typeof/typeof.hpp> typedef BOOST_TYPEOF(obj) ObjType;
, "" . sizeof , . ++ , , . , "GetNumMembers()" "GetMemberSize (index)" .., , ...
" ++", Boost. Qaru " ++".
Boost
++ . Deserialization .
My experience, requiring class and member names, comes from printing debugging information. Class and field names would be useful in handling exceptions, especially when they are thrown.