About c++11 range for loops and iterators

前端 未结 1 860
囚心锁ツ
囚心锁ツ 2021-01-28 04:42

What does the c++11 range for loops do that cause this:

std::list item;
....
//fill the list somewhere else
....
for(Point p : item) {
         


        
相关标签:
1条回答
  • 2021-01-28 05:09

    In your former code, the line

    for(Point p : item) {
    

    creates copies of the point every time you access the next item. To make sure that your calling of method lowerY() works, you need to redefine it as

    for(Point & p : item) {
    
    0 讨论(0)
提交回复
热议问题