This code shows that the resize member function is calling the null constructor even when the size does not need to be changed.
#include <vector> #include <iostream> class c { public: c() { std::cerr << "c null constructor called\n"; } c(int i) : i(i) {} int i; }; int main() { std::vector<c>f; f.push_back(c(0)); f.resize(1); return 0; } -- Summary: vector::resize unnecessarily calls null constructor Product: gcc Version: 4.4.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: igodard at pacbell dot net http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42242