变量作为C ++ 11属性参数

Mat*_*adu 1 c++ c++11 eos

给定一个接受字符串参数的属性,例如[[deprecated("reason")]],是否可以使用除硬编码字符串文字之外的其他任何东西?

就我而言,我正在为EOS.IO区块链开发一个智能合约,该合约公开了该[[eosio::on_notify("account::action")]]属性,我想将其提取到"account::action"配置文件中。

我知道有一个EOS.IO特定的Stack Exchange网络,但是我认为这个问题适用于所有C ++ 11属性。

到目前为止的尝试

我尝试将这些参数定义为config.hpp标头中名称空间中的静态const字符串:

// ...omitting irrelevant parts

namespace config {
    static const std::string test = "eosio.token::transfer";
}
Run Code Online (Sandbox Code Playgroud)

然后导入标头并使用静态字符串:

// contract.cpp

// ...omitting irrelevant parts

#include "config.hpp"

class [[eosio::contract]] myapp : public contract {
public:

    [[eosio::on_notify(config::test)]]
    void on_transfer();
};
Run Code Online (Sandbox Code Playgroud)

但是,编译器抱怨:

错误:“ on_notify”属性需要字符串[[eosio :: on_notify(config :: test)]]

Lig*_*ica 5

没有。

属性从字面上被烘焙到您的源代码中。

不过,您可以在构建系统的帮助下使用预处理器来定义所需的宏。