使用 C++11 属性 [英] using C++11 attributes

查看:64
本文介绍了使用 C++11 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能否解释一下如何从 C++ 中的属性中获取信息?例如,我想编写 C++ 到 python 绑定.为此,我需要用一些特定的绑定信息来注释类中的所有方法.现在我需要按属性生成一些代码.或者另一个例子,将类映射到数据库实体.还是 C++11 的属性与 Java 或 C# 中的注解不一样?

Could you please explain how to get information from attributes in C++? For example, I want to write C++ to python binding. For this I need to annotate all methods in class with some specific binding info. Now I need to generate some code by attributes. Or another example, map class to db entity. Or C++11 attributes is not the same as in Java or C# annotations?

推荐答案

属性(新的 C++11 功能) 只是编译器扩展的标准化语法.要执行您想要的操作,您需要一个具有适当扩展名的编译器.到目前为止,我认为任何编译器都没有实现属性语法,更不用说 Python 绑定的任何特定属性了.

Attributes (a new C++11 feature) are just a standardized syntax for compiler extensions. To do what you want you would need a compiler with the proper extensions. So far, I don't think any compiler even implements attribute syntax, much less any specific attributes for Python bindings.

因为它们是为编译器扩展而设计的,所以没有创建自己的属性的标准方法,就像使用 Java 注释或 C# 属性一样.当然,编译器可以提供这种能力作为扩展... ;)

Because they're intended for compiler extensions, there's no standard way of creating your own attributes, like you can with Java annotations or C# attributes. Of course, a compiler could provide this ability as an extension... ;)

这篇关于使用 C++11 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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