Setting vector elements in range-based for loop

后端 未结 4 1284
南旧
南旧 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:13

    you have to write

    for( auto& n : *CTdata )
    

    because auto n means short int n when you need short int& n. i recommend you to read difference beetween decltype and auto.

提交回复
热议问题