我遇到了一些代码,如下所示:
#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类中?