I wanted to see if I could initialize a vector of objects in a single line, so I wrote the following example:
vector<Bar*> bar(5, new Bar());
bar[3]->hit++;
for (int i = 0; i < 5; i++)
cout << bar[i]->hit << endl;
But when I run it, I get:
1
1
1
1
1
It seems to use the same new Bar() for all the pointers. Is it possible to initialize vectors of object pointers to point to different objects?
std::generatemagic, but the question is, why would you want to? - avakar