How does std::vector copy objects to its internal storage
问题 I have the following problem: void add(){ cRow Row(); Row.add("Column", "Value"); std::vector<cRow> mRows; mRows.push_back(Row); } cRow::cRow(): mCol(NULL), mVal(NULL) { } cRow::add(const char* Col, const char* Val){ mCol = strdup(Col); mVal = strdup(Val); } cRow::~cRow(){ free(mCol); free(mVal); } After adding the local variable Row to the vector, the destructor is called for that Row and the strings are freed. Obviously, the pointers to the strings of the stored row in the vector are now