q09*_*987 8 c++ destructor exception throw specifier
namespace QuantLib {
//! Base error class
class Error : public std::exception {
public:
/*! The explicit use of this constructor is not advised.
Use the QL_FAIL macro instead.
*/
Error(const std::string& file,
long line,
const std::string& functionName,
const std::string& message = "");
/*! the automatically generated destructor would
not have the throw specifier.
*/
~Error() throw() {}
//! returns the error message.
const char* what() const throw ();
private:
boost::shared_ptr<std::string> message_;
};
}
Run Code Online (Sandbox Code Playgroud)
正如您在注释中看到的那样,类的析构函数Error显式提供了一个带有no-throw说明符的空实现.
问题:这有必要吗?或者这是一个很好的做法,比较让编译器生成隐式析构函数?
在C++ 11中,析构函数是隐式的throw()(除非该类型的任何成员或基类具有带有不同异常规范的析构函数),因此如果您在C++ 11模式下进行编译则没有必要.
如果你在C++ 03中,你可能想要添加它,但是它是否会产生效果是非常实现的定义...现在,为了文档目的你可能想要添加它,但同样,它通常是假设析构函数不抛出.
| 归档时间: |
|
| 查看次数: |
2838 次 |
| 最近记录: |