代码之家  ›  专栏  ›  技术社区  ›  Tony The Lion

C++宏定义不清楚

  •  3
  • Tony The Lion  · 技术社区  · 15 年前

    这是一个类的宏定义还是它到底是什么?

    #define EXCEPTIONCLASS_IMPLEMENTATION(name, base, string) : public base     \
        {                                                               \
    public:                                                                 \
        name() : base(string) {}                                            \
        name(const x::wrap_exc& next) : base(string,next) {};               \
        name(const x::wrap_exc& prev, const x::wrap_exc& next) :            \
            base(prev, next) {};                                            \
    }
    
    2 回复  |  直到 15 年前
        1
  •  9
  •   johnsyweb    15 年前

    异常类的宏定义。

    看起来有人想让你写这样的代码:

    class my_exception EXCEPTIONCLASS_IMPLEMENTATION(my_exception, std::exception, "What a mess!")
    

    预处理器将显示:

    class my_exception : public std::exception { public: my_exception() : std::exception("What a mess!") {} my_exception(const x::wrap_exc& next) : std::exception("What a mess!",next) {}; my_exception(const x::wrap_exc& prev, const x::wrap_exc& next) : std::exception(prev, next) {}; }
    

    到底是什么?

    这是可憎的!

        2
  •  3
  •   Andrey    15 年前

    它是用于异常的宏,用标准构造函数创建异常。