Name: Anonymous 2011-02-23 21:22
#include <string>
#include <vector>
#include <iostream>
std::vector<std::string> names;
void addNames()
{
names.push_back(std::string("Foo"));
names.push_back(std::string("Bar"));
}
int main(int argc, char **argv)
{
addNames();
for (int i = 0, size = names.size(); i < size; ++i)
{
std::cout << names[i] << std::endl;
}
return 0;
}Output:
Foo
BarOkay so what I'm trying to understand is since I'm pushing anonymous stack string objects onto the vector, I'm assuming that the strings will also have their destructors called (because local variables). This should also destroy the internal char sequence.
Yet the strings remain intact when printing the vector (so somehow its being copied?). So /prog/ please show me your sepples mastery and explain the magic here.