#define constexpr in C ++

时间:2018-01-30 02:34:14

标签: c++ c++11

我遇到了一些代码,如下所示:

#define set_opcode(name) \
    constexpr static auto get_opcode() noexcept \
    { \
        return OpcodeValue::name; \ //OpcodeValue is some enum
    }

class NoopOpcode : public Opcode
{
public:
    set_opcode(NOOP);

    std::string serialize() const noexcept override;

    bool deserialize(const std::string &serialized) noexcept override;

    void execute(state::State &state) const noexcept override;

};


class InvOpcode : public Opcode
{

private:

    Int _item_id{};

    Int _item_count{};



public:

    set_opcode(INV);

    std::string serialize() const noexcept override;

    bool deserialize(const std::string &serialized) noexcept override;

    void execute(state::State &state) const noexcept override;

};

使用#define声明constexpr的原因/好处是什么?

与明确声明get_opcode(){return OpcodeValue :: NOOP;例如,在NoopOpcode类中?

0 个答案:

没有答案