Let's say I have a loop like this:
vector<shared_ptr<someStruct>> vec;
int i = 0;
while (condition)
{
i++
shared_ptr<someStruct> sps(new someStruct());
WCHAR wchr[20];
memset(wchr, i, 20);
sps->pwsz = wchr;
vec.push_back(sps);
}
At the end of this loop, I see that for each sps
element of the vector, sps->pwsz
is the same. Is this because I'm passing a pointer to memory allocated in a loop, which is destructed after each iteration, and then refilling that same memory on the next iteration?