【问题标题】:In C++ programming, is the main() function static like in java or non-static like in C?在 C++ 编程中,main() 函数是像 java 中的静态函数还是像 C 中的非静态函数?
【发布时间】:2021-10-18 15:06:37
【问题描述】:

在 C++ 编程中,main() 函数是像 java 中的静态函数还是像 C 中的非静态函数?

【问题讨论】:

  • 在Java中,它是一个类的静态成员函数。在 C++ 中,它不是任何类的成员。 C 根本没有成员函数。 Java 中不存在 C 和 C++ 的静态链接。 (“static”关键字在不同语言中的含义非常不同,在 C++ 中有几个含义。)
  • 会有什么不同?您不能从另一个函数调用main。您无法获得指向 main 的函数指针。
  • static 在这些语言中的含义不同。 “sea”这个词是德语中的代词还是西班牙语中的“yes”?

标签: c++ function static c++17 main


【解决方案1】:

来自https://timsong-cpp.github.io/cppwp/n3337/basic.start.main#1

一个程序应包含一个名为main的全局函数,它是程序的指定开始。

它不能是static 函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-18
    • 1970-01-01
    • 1970-01-01
    • 2013-12-20
    • 2011-07-16
    相关资源
    最近更新 更多