Setting vector elements in range-based for loop

后端 未结 4 1192
南旧
南旧 2020-11-28 16:50

I have come across what I consider weird behaviour with the c++11 range-based for loop when assigning to elements of a dynamically allocated std::vector. I hav

4条回答
  •  有刺的猬
    2020-11-28 17:30

    Change this loop statement

    for(auto n: *CTdata)
    

    to

    for(auto &n : *CTdata)
    

    that is you have to use references to elements of the vector.

提交回复
热议问题