using C++11 attributes(使用 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 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 C++11 属性


基础教程推荐
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- CString 到 char* 2021-01-01