C++语言特性:在class或方法声明中使用双方括号[[]]
C++ language feature: double square brackets [[ ]] used in class or method declaration
我目前正在研究 eosio 的智能合约开发。通过浏览教程,我注意到了一个我以前从未见过的 C++ 语言特性:
#include <eosio/eosio.hpp>
using namespace eosio;
class [[eosio::contract]] hello : public contract {
public:
using contract::contract;
[[eosio::action]]
void hi( name user ) {
print( "Hello, ", user);
}
};
我的问题是class声明中的[[eosio::contract]]
和方法声明中的[[eosio::action]]
是什么意思?此 C++ 语言功能的术语是什么?
What is the term for this C++ language feature?
双方括号是属性的语法。它们在 C++ 标准部分中指定 [dcl.attr]:
[dcl.attr]
Attributes specify additional information for various source constructs such as types, variables, names, blocks, or translation units.
My question is what does the [[eosio::contract]] in the class declaration and the [[eosio::action]] in the method declaration mean?
eosio
是一个非标准的属性命名空间,因此您应该查阅他们的文档以了解其自定义属性的含义。
我目前正在研究 eosio 的智能合约开发。通过浏览教程,我注意到了一个我以前从未见过的 C++ 语言特性:
#include <eosio/eosio.hpp>
using namespace eosio;
class [[eosio::contract]] hello : public contract {
public:
using contract::contract;
[[eosio::action]]
void hi( name user ) {
print( "Hello, ", user);
}
};
我的问题是class声明中的[[eosio::contract]]
和方法声明中的[[eosio::action]]
是什么意思?此 C++ 语言功能的术语是什么?
What is the term for this C++ language feature?
双方括号是属性的语法。它们在 C++ 标准部分中指定 [dcl.attr]:
[dcl.attr]
Attributes specify additional information for various source constructs such as types, variables, names, blocks, or translation units.
My question is what does the [[eosio::contract]] in the class declaration and the [[eosio::action]] in the method declaration mean?
eosio
是一个非标准的属性命名空间,因此您应该查阅他们的文档以了解其自定义属性的含义。