本文介绍了C ++中的松散抛出指定符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 此错误是什么意思?我该如何解决?这是导致它的标头代码: class BadJumbleException:公共异常{ public: BadJumbleException (const string& msg); //构造函数,接受字符串作为消息 string&什么(); //返回消息字符串 private:字符串message; //存储异常消息}; 这是源代码: BadJumbleException :: BadJumbleException(const string& m):message(m){} string& BadJumbleException :: what(){返回消息; } 编辑:这是错误: '虚拟BadJumbleException ::〜BadJumbleException() 解决方案 div> 在C ++ 03中,按照§ 18.6.1 / 5, std :: exception 具有一个声明为不会引发任何异常的析构函数(将导致编译错误)。 该语言要求,当您从此类类型派生时,您自己的析构函数必须具有相同的限制: 虚拟BadJumbleException ::〜BadJumbleException()throw(){} // ^^^^^^^ 这是因为重写函数可能没有更小的抛掷规范。 在C ++ 11中, std :: exception ::〜exception 在库代码中被 not 明确标记为 throw()(或 noexcept ),但是默认情况下,所有析构函数均为 noexcept(true)。 自该规则将包含您的析构函数并允许您的程序进行编译,这使我得出结论,您不是em>真的编译为C ++ 11。 What does this error mean? How can I fix it? This is the header code that's causing it:class BadJumbleException : public exception {public: BadJumbleException (const string& msg); // Constructor, accepts a string as the message string& what(); // Returns the message stringprivate: string message; // Stores the exception message};And this is the source code:BadJumbleException::BadJumbleException (const string& m) : message(m) {}string& BadJumbleException::what() { return message; }EDIT: This is the error: looser throw specifier for 'virtual BadJumbleException::~BadJumbleException() 解决方案 In C++03, per §18.6.1/5, std::exception has a destructor that is declared such that no exceptions can be thrown out of it (a compilation error will be caused instead).The language requires that when you derive from such a type, your own destructor must have the same restriction:virtual BadJumbleException::~BadJumbleException() throw() {}// ^^^^^^^This is because an overriding function may not have a looser throw specification.In C++11, std::exception::~exception is not marked throw() (or noexcept) explicitly in the library code, but all destructors are noexcept(true) by default.Since that rule would include your destructor and allow your program to compile, this leads me to conclude that you are not really compiling as C++11. 这篇关于C ++中的松散抛出指定符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-30 02:29