std::vector and copy constructors

前端 未结 4 1163
广开言路
广开言路 2020-12-19 09:04
vector v;
X x;
v.push_back(x); v.push_back(x); v.push_back(x);

Why this code calls the copy constructor of a class X

4条回答
  •  粉色の甜心
    2020-12-19 09:29

    You can use vector reserve to create space in the vector before hand to speed up adding elements to a vector as well as stopping this from happening.

提交回复
热议问题