c++ - main() 可以有异常规范吗?

标签 c++ c++11 program-entry-point exception-specification

在标准 C++ 中,main 函数可以有异常规范吗?

例如,以下是否合法?

int main() noexcept {}

最佳答案

是的,这是完全合法的。 C++ 标准(在 [basic.start.main][except.spec] 或其他地方)中没有禁止这样做的措辞。

即使在异常规范是函数类型的一部分的 C++17 及更高版本中,main 也仅根据 [basic.start.main#2] 限制其链接和返回类型。 :

An implementation shall not predefine the main function. This function shall not be overloaded. Its type shall have C++ language linkage and it shall have a declared return type of type int, but otherwise its type is implementation-defined.

关于c++ - main() 可以有异常规范吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43885942/

相关文章:

c++ - 派生 QT 类的复制构造函数

c++ - 这是一个糟糕的设计吗?

c++ - 是否存在标准调用约定?

c++ - 用 range-v3 替换数据

c - 在 C 中,如何计算一个函数中的局部变量,在另一个函数中?

c++ - 在 C++ 中从 %f 中删除前导和尾随零

c++ - for 循环可以在其语句中进行赋值吗?

c++ - 使用 map 将字符串与枚举连接起来

c++ - 如何从另一个 .cpp 源文件调用 main.cpp 中定义的方法?

java - 包裹main方法的类的作用是什么?