C++11 range based loop: How does it really work

前端 未结 3 1780
梦毁少年i
梦毁少年i 2020-12-03 22:02

I know how this loop works, and how I can use it in practical problems. But I want to know what is happening under the hood. I thought that this loop was similar to a regula

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 22:27

    Every iteration of the loop creates a local variable x and initializes it to the next element of vec. When the loop iteration ends, x goes out of scope. A single x is never modified.

    See this link for the precise semantics.

提交回复
热议问题