I have an object called LastQueryInfo lastQuery
in my class. Every time this object changes, I add it to a vector called history
.
Initially, when I did history.push_back(lastQuery)
I didn't know what would happen - is the vector going to make a copy of the object? or is it going to keep a reference to it? So if later I modify lastQuery, are all the objects (assuming they are references) in the history vector going to be modified?
After some testing, I found that history.push_back(lastQuery)
is indeed going to make a copy of the object, then add it to the vector. But how can I know that without doing any tests? How can I know when C++ is going to make a copy, and when it's going to add the actual object?