我遇到了麻烦:意思。 [英] I am having trouble with : meaning.
本文介绍了我遇到了麻烦:意思。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在此示例中分号的含义>> for(const auto& value:1st)
what does the semicolon mean in this example >> for (const auto& value : 1st)
#include <initializer_list>
using namespace std;
int makeSum(initializer_list<int> 1st)
{ int total= 0;
for (const auto& value : 1st) { //Right here
total += value; }
return total; }
我尝试过:
我试着在这里一次又一次地问。
What I have tried:
I tried to ask here, again and again.
推荐答案
不再是帮助吸血鬼了。你要么学会做自己的研究,要么就是在错误的课堂上。编写代码需要你做大量的研究,如果你要在这个行业生存。
现在,再一次,这是一个COLON,而不是一个分号。
接下来,如果您使用Google搜索C ++ for const auto,您会发现您正在查看基于范围的for循环。
阅读基于范围的文档循环 [ ^ ],你会看到冒号后的表达式应该是一个范围表达式,或者返回一系列对象的东西。这也称为列表,您需要按照makeSum函数头中的描述传入。
Stop being a help vampire. You either learn to do your own research or you're in the wrong class. Writing code requires you to do a LOT of research if you're going to survive in this business.
Now, again, that is a COLON, not a semicolon.
Next, if you would have Googled for "C++ for const auto", you would have found out that you're looking at a range-based for loop.
Reading the documentation on a range-based for loop[^], you would have seen that the expression after the colon is expected to be a "range expression", or something that returns a range of objects. This is also known as a "list", which you are expected to pass in as described in your makeSum function header.
正如戴夫所说,不再是帮助吸血鬼。转到 C ++语言参考| Microsoft Docs [ ^ ]并努力学习该语言。
As Dave says, "stop being a help vampire". Go to C++ Language Reference | Microsoft Docs[^] and make an effort to actually learn the language.
这篇关于我遇到了麻烦:意思。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文