Values in STL containers are stored by-value. If you have a vector like this:
class BigObject
{
...
};
vector<BigObject> myObjs;
myObjs.push_back(obj1);
myObjs.push_back(obj2);
...
The vector will make a copy of the object you're pushing in. Also in the case of a vector, it may make new copies later when it has to reallocate the underlying memory, so keep that in mind.
The same thing is true when you have a vector of pointers, like vector<char*>
-- but the difference here is that the value that is copies is the pointer, not the string it points to. So if you have:
vector<char*> myStrings;
char* str = new char[256]; // suppose str points to mem location 0x1234 here
sprintf(str, "Hello, buffer");
myStrings.push_back(str);
delete [] str;
...the vector will get a copy of the pointer. The pointer it gets will have the same value (0x1234), and since you delete
d that pointer after pushing in the pointer, your vector contains a wild pointer and your code will eventually crash (sooner than later, hopefully).
Which, by the way, could have been avoided if instead of using char*s you used strings:
typedef vector<string> strings;
strings myStrings;
myStrings.push_back("Hello, buffer");