我偶然写下了以下内容并且没有使用gcc 8发出警告:
auto f = []() bool {};
Run Code Online (Sandbox Code Playgroud)
我从未听过或读过有关以前语法的任何内容.我的意图是写:
auto f = []() -> bool {};
Run Code Online (Sandbox Code Playgroud)
在这种情况下,gcc发出了我预期的非常有用的警告:no return statement.
我做了一些实验,GCC接受了第一种语法,没有任何警告或错误,因为至少是GCC 7.1,而不是GCC 6.3.没有其他编译器似乎接受它.此外,本机类型接受第一种语法:bool int float这样但不适用于类等struct A {};
这是一个错误还是这是一个新的c ++ 17或c ++ 20语法,例如属性?
在c ++ 17中引入,std::filesystem::u8path似乎在c ++ 20中被弃用了.
这个选择的原因是什么?我应该在c ++ 17中使用什么?我应该在c ++ 20中使用什么?
我想要一个向量数组,其中0作为所有单个向量中的单个元素.有更有效的方法吗?这有用吗?
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int lastAnswer = 0;
int n,q;
cin >> n >> q;
vector<int> seqArr[n];
for(int i=0;i<n;i++)
{
fill(seqArr[i].begin(),seqArr[i].end(),0);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)