c++中的松散抛出说明符
Looser Throw Specifier in C++
这个错误是什么意思?我该怎么修理它?这是导致它的头代码:
class BadJumbleException : public exception {
public:
BadJumbleException (const string& msg); // Constructor, accepts a string as the message
string& what(); // Returns the message string
private:
string message; // Stores the exception message
};
源代码:
BadJumbleException::BadJumbleException (const string& m) : message(m) {}
string& BadJumbleException::what() { return message; }
编辑:这是错误:
松散抛出指定符'virtual BadJumbleException::~BadJumbleException()
在c++ 03中,per §18.6.1/5, std::exception
有一个析构函数,它被声明为不能抛出异常(相反会引起编译错误)。
该语言要求,当从这样的类型派生时,您自己的析构函数必须具有相同的限制:
virtual BadJumbleException::~BadJumbleException() throw() {}
// ^^^^^^^
这是因为重写函数可能没有松散抛出规范。
在c++ 11中,std::exception::~exception
是而不是在库代码中显式标记为throw()
(或noexcept
)的,但是所有析构函数默认都是noexcept(true)
。
由于该规则将包含您的析构函数并允许您的程序编译,因此我得出结论,您的并没有真正编译为c++ 11。
相关文章:
- 激励'inline'说明符的真实世界示例?
- 缺少类型说明符,显式类型为"缺少错误"
- 为什么mpfr_printf与十六进制浮点(%a转换说明符)的printf不同
- 叮叮当当在修复时插入多个"覆盖"说明符
- 编译器错误:destuctor 的更宽松的抛出说明符
- 使用说明符 extern 声明的C++中的标识符链接
- 同时具有"外部"和"内联"说明符的变量
- 与 tesseract::TessBaseApi() 相关的 Tesseract-OCR 出错(预期的类型说明符)
- 错误:不能使用"显式"说明符声明 bool'
- 基于范围的 for 循环range_declaration中各种说明符之间的性能差异
- 为什么转换函数声明不需要至少一个定义类型说明符
- NOEXCEPT 函数调用运算符的说明符_Not_fn
- 参数包内 noexcept 说明符
- C++需要所有声明的类型说明符和预期的非限定 id(需要调试帮助)
- 格式说明符C++有什么问题
- 0x%08lx 格式说明符在 printf 语句到 cout
- 私钥解密代码使用公共接口说明符到 BSAFE 库 v6.0?
- 在 CRTP 中使用嵌套名称说明符
- 函数模板签名中忽略的成员类型def 的访问说明符
- VS2019 C++未知覆盖说明符