问题描述
在 C++ 中,无法获取有关类成员变量的信息。这使得自动序列化等功能难以实现。似乎将此功能添加到语言中很简单。毕竟 typeid
和 std::typeinfo
使得获取类型的唯一标识符成为可能。要说明此类功能的工作原理,请参见下文:
// An integer constant corresponding to the number of members in the struct
type_members(A)::count
// An array of type_info corresponding to the members in the struct
type_members(A)::typeids
// An array of null terminated char* corresponding to the names of the members
type_members(A)::names
// Ann array of T A::* corresponding to the memory offsets of the members
// Where T is the type of the member at that index
type_members(A)::members
是否有人讨论过在 C++ 标准中添加与此类似的功能?如果已经考虑并拒绝了这样的功能,为什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)