【发布时间】:2013-07-16 15:52:24
【问题描述】:
我对 C++ 相当陌生,并且发现以下代码 sn-p 用于从 std::exception 扩展的自定义异常。我不明白的唯一部分是构造函数定义之后的: err_msg(msg) {}。谁能解释为什么这不在函数大括号中?
class my_exception : public std::exception {
private:
std::string err_msg;
public:
my_exception(const char *msg) : err_msg(msg) {};
~my_exception() throw() {};
const char *what() const throw() { return this->err_msg.c_str(); };
};
【问题讨论】:
标签: c++ exception custom-exceptions