gpt4 book ai didi

c++ - "Expected initializer before ' : ' token" with range-based for

转载 作者:搜寻专家 更新时间:2023-10-31 02:10:40 25 4
gpt4 key购买 nike

#include <iostream>
#include <array>
using namespace std;

typedef int type;
typedef array <type,6> Liste;
bool appartient(type element, Liste liste);

int main()
{
Liste maliste = {4,5,-3,12,7,-33};

cout << appartient(13, maliste) << endl;
cout << appartient(12, maliste) << endl;
return 0;
}

bool appartient(type x, Liste liste)
{
for (auto element: liste) { //////this line!!!!!!!
if (x == element) return true;
}
return false;
}

我正在用 C++ 做这个表格练习。在这里,我正在编写一个功能“appartient”,用于验证列表中元素的外观。但是我在这个函数中有一些错误:

1/错误:':' 标记之前的预期初始值设定项

2/错误:'return' 前需要主表达式

3/错误:应为 ';'在“返回”之前

4/错误:'return' 前需要主表达式

5/错误:在“return”之前需要“)”

为什么?

最佳答案

显然你的编译器不支持range-based for-loops ,至少不是您正在使用的选项。

基于范围的是 supported自 GCC v4.6、Clang v3.0、MSVC v17.0、eccp v4.5、Intel C++ v13.0、IBM XLC++ v13.1.2、Sun/Oracle C++ 5.13、Cray v8.4、PGI 2015 和 HP aCC A.06.28.

检查您的编译器是否是最新的,并查看其手册以了解如何激活 C++11 支持。

关于c++ - "Expected initializer before ' : ' token" with range-based for,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44910788/

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