smart-pointer

Dynamic memory allocation and smart pointers

How can I allocate memory for an array using shared_ptr? I tried to do something like this, but it crashes when executed. # ... ; ++i) array[i] = i; for (unsigned int i = 0; i < size; ++i) cout << array[i] << " "; return 0; }

I can't add a smart pointer to the vector

There is a class MyClass, of course, with a constructor, you need to create a vector of smart pointers to objects of this cla ... nique_ptr<MyClass> p1(new MyClass); // до этого момента всё в порядке vectorPtr.push_back(p1); return 0; }

How does std::weak ptr work?

If initially std::weak_ptr pointed to the null pointer std::shared_ptr: std::shared_ptr<Ptr> ptr = nullptr; std::weak_ ... this smart pointer is later changed from a non-null pointer to an existing one, weak the pointer will not change its state?