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

查看:112
本文介绍了如何添加反射到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的fork,使用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天全站免登陆