Click here to Skip to main content
15,887,915 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
what does the semicolon mean in this example >> for (const auto& value : 1st)

C++
#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.
Posted
Updated 16-Dec-18 22:52pm
v3
Comments
nv3 17-Dec-18 3:51am    
And replace that "1st" by "lst" -- in C++ identifiers don't start with a digit! It almost looks the same, but makes a great difference. That's what happens when one just copies things and doesn't try to understand what's going on.

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.
 
Share this answer
 
Comments
CPallini 17-Dec-18 3:24am    
5.
As Dave says, "stop being a help vampire". Go to C++ Language Reference | Microsoft Docs[^] and make an effort to actually learn the language.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900