如何向 C++ 应用程序添加反射? [英] How can I add reflection to a C++ application?

查看:46
本文介绍了如何向 C++ 应用程序添加反射?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够内省 C++ 类的名称、内容(即成员及其类型)等.我在这里谈论的是本机 C++,而不是具有反射的托管 C++.我意识到 C++ 使用 RTTI 提供了一些有限的信息.哪些额外的库(或其他技术)可以提供这些信息?

I'd like to be able to introspect a C++ class for its name, contents (i.e. members and their types) etc. I'm talking native C++ here, not managed C++, which has reflection. I realise C++ supplies some limited information using RTTI. Which additional libraries (or other techniques) could supply this information?

推荐答案

Ponder 是一种 C++ 反射图书馆,回答这个问题.我考虑了这些选项并决定自己做一个,因为我找不到一个能满足我所有要求的选项.

Ponder is a C++ reflection library, in answer to this question. I considered the options and decided to make my own since I couldn't find one that ticked all my boxes.

尽管这个问题有很好的答案,但我不想使用大量的宏,也不想依赖 Boost.Boost 是一个很棒的库,但是有很多小型的定制 C++0x 项目更简单并且编译时间更快.能够在外部装饰类也有一些好处,比如包装一个(还?)不支持 C++11 的 C++ 库.它是 CAMP 的分支,使用 C++11,不再需要 Boost.

Although there are great answers to this question, I don't want to use tonnes of macros, or rely on Boost. Boost is a great library, but there are lots of small bespoke C++0x projects out that are simpler and have faster compile times. There are also advantages to being able to decorate a class externally, like wrapping a C++ library that doesn't (yet?) support C++11. It is fork of CAMP, using C++11, that no longer requires Boost.

这篇关于如何向 C++ 应用程序添加反射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆