c++ - 我是否也仅在函数头或声明中指定异常类型? (C++)

标签 c++ exception throw

  SVector.H:

  void pop_back() throw (underflow_error);

在我的 SVector.cpp 文件中,我是否也应该包含 throw (underflow_error) 部分?

void pop_back() throw (underflow_error)
{
    // implementation
}

void pop_back()
{
    // implementation
}

谢谢。

最佳答案

15.4/2:

If any declaration of a function has an exception-specification, all declarations, including the definition and an explicit specialization, of that function shall have an exception-specification with the same set of type-ids.

关于c++ - 我是否也仅在函数头或声明中指定异常类型? (C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2436908/

相关文章:

c++ - gmtime 同时改变两个指针

c++ - 可以在刷新操作中写入文件失败

c++ - 你如何调试 MinGW 异常处理?

ruby-on-rails - 全局错误处理和包含的rescue_from的顺序

java - 使用 throw 关键字时出现编译错误

sql - 我无法使用 THROW SQL Server 2008 R2

c++ - 正确编写基于范围的构造函数

c++ - 可执行/in) 代码处无法到达的断点

c# - 抛出无效对象状态的异常是什么?

C++ 抛出异常