在标准 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 typeint
, but otherwise its type is implementation-defined.
关于c++ - main() 可以有异常规范吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43885942/