gpt4 book ai didi

c++ - 命名空间中的主要内容

转载 作者:IT老高 更新时间:2023-10-28 12:42:14 26 4
gpt4 key购买 nike

为什么不编译?链接器找不到main,但是为什么会这样呢?

namespace somenamespace{

int main(void){
return 0;
}

}

最佳答案

3.6.1/1 - "A program shall contain a global function called main, which is the designated start of the program. It is implementation-defined whether a program in a freestanding environment is required to define a main function. [ Note: in a freestanding environment, start-up and termination is implementation-defined; startup contains the execution of constructors for objects of namespace scope with static storage duration; termination contains the execution of destructors for objects with static storage duration. —end note ]

您的示例将“main”(用作程序入口点)作为命名空间函数,因此您的代码格式错误。这并不意味着不能像您那样定义函数“main”。这只是意味着 独立程序需要根据标准定义的签名对“main”进行全局命名空间范围定义。 托管程序

关于c++ - 命名空间中的主要内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3956678/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com