c++ - C++中的成员反射列表
问题描述
在 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++ 标准中添加与此类似的功能?如果这样的功能已被考虑并拒绝,为什么?
解决方案
推荐阅读
- .net-core - 任务计划程序创建任务 DotNet 不起作用
- python - 是否可以在海龟对象中使用索引?
- javascript - 利用本地存储存储购物车详细信息的更好方法
- javascript - 正确使用未定义
- python - 如何抓取 youtube 视频以获取比一页更多的视频?
- sql - 检查是否在多值参数中选择了逗号分隔列表中的任何值(在 SQL 数据集中)
- r - 将字符串的前两个字符移到字符串中的特定字符之后
- java - 如何在 CQL 中使用 JAVA 创建表并插入 json 数据?
- ember.js - 我可以将路由映射/重定向到 Ember FastBoot 应用服务器中的端口吗?
- redux-observable - 如何等待其他史诗完成然后调用回调?