Example of C++ std::vector<std::auto_ptr<T>> that compiles but fails

  auto-ptr, c++, unique-ptr, vector

What would be a simple C++ program where a std::vector<std::auto_ptr<T>> compiles but fails to execute correctly, but where the same program with std::vector<std::uniq_ptr<T>> compiles and works correctly, for some data type T? I know that std::auto_ptr has been deprecated or removed; I just want an example involving containers to motivate why it was deprecated or removed. I’m using g++-10 -std=c++20 on MacOS Big Sur version 11.2.1. Thank you very much in advance.

Source: Windows Questions C++

LEAVE A COMMENT