What is the difference between &vector[0] and vector.begin()?

前端 未结 3 1302
故里飘歌
故里飘歌 2021-01-13 07:50

This question is related with item 16 of effective stl book which states that while using vector(lets assume vectorvec) instead of array in a legacy

3条回答
  •  情话喂你
    2021-01-13 08:33

    Formally, one produces an iterator, and the other a pointer, but I think the major difference is that vec[0] will do bad stuff if the vector is empty, while vec.begin() will not.

提交回复
热议问题