I have a piece of code like this:
class Data
{
public:
Data(const std::vector<int> &_data)
{
my_data = _data;
}
private:
std::vector<int> my_data;
};
int main()
{
std::vector<std::shared_ptr<Data>> vec = {
std::shared_ptr<Data>(new Data(std::vector<int>({ 1, 2 ,3 }))),
std::shared_ptr<Data>(new Data(std::vector<int>({ 3, 4 ,5 })))
};
// breakpoint
return 0;
}
somehow when I pause the program to check values (at breakpoint), the first (vec[0]
) element is destroyed while the second one (vec[1]
) is fine. What is going on here? Is that a bug in compiler? I am using new Visual Studio 2013.