相关疑难解决方法(0)


What is the proper declaration of main?

What is the proper signature of the main function in C++? What is the correct return type, and what does it mean to return a value from main? What are the allowed parameter types, and what are their meanings?

这是系统特定的吗?这些规则会随着时间而改变吗?如果我违反它们会发生什么?

c++ program-entry-point c++-faq

144
推荐指数
2
解决办法
9万
查看次数

将自动退货类型扣除工作为主?

我能否在C++ 1y(C++ 14)中为main函数执行以下操作:

auto main()
{
    // ...
}
Run Code Online (Sandbox Code Playgroud)

int即使我们不需要使用显式,返回类型也会自动生成return 0;吗?

c++ c++14

27
推荐指数
1
解决办法
877
查看次数

C++中main()的法律定义14

关于main()[3.6.1] ,我能够找到的C++ 14的最后一个草案说:

实现不应预定义主函数.此功能不应过载.它应该具有int类型的返回类型,否则其类型是实现定义的.所有实现都应允许两者

- 返回int和的函数()

- 返回int的函数(int,指向char的指针)

及(第5段)

如果控制到达main的末尾而没有遇到return语句,则效果就是执行

return 0;

这是否意味着以下所有内容都是合法的C++ 14最小程序?如果没有,为什么不呢?

  1. auto main() -> int {}
  2. auto main() { return 0; }
  3. auto main() {}

c++ program-entry-point language-lawyer c++14

22
推荐指数
1
解决办法
1586
查看次数

哪个草案最接近C++ 14标准?

我在不同的地方看过N3690,N4140和N4296.我猜它是N4140,因为它是在2014年底发布的.N4296似乎有不像C++ 14那样的东西,就像折叠表达式一样.

c++ c++14

20
推荐指数
1
解决办法
1751
查看次数

函数定义后"const - > std :: string const&"的含义是什么?

C++ Primer,第5版中阅读一个练习的答案,我找到了这段代码:

#ifndef CP5_ex7_04_h
#define CP5_ex7_04_h
#include <string>

class Person {
std::string name;
std::string address;
public:

auto get_name() const -> std::string const& { return name; }
auto get_addr() const -> std::string const& { return address; }
};

#endif
Run Code Online (Sandbox Code Playgroud)

是什么

const -> std::string const& 
Run Code Online (Sandbox Code Playgroud)

这个意思是什么意思?

c++ c++14

14
推荐指数
2
解决办法
1366
查看次数