Why it is not possible to use an initializer_list to initialize a vector of unique_ptr's? [duplicate]
问题 This question already has answers here : initializer_list and move semantics (8 answers) Closed 6 years ago . I'm wondering why initializer_list doesn't work with unique_ptr: std::vector<std::unique_ptr<int>> vptr = {std::make_unique<int>(1), std::make_unique<int>(2)}; do not compile. However: std::vector<std::unique_ptr<int>> vptr(2); vptr[0] =std::make_unique<int>(1); vptr[1] =std::make_unique<int>(2); compile. and std::vector<int*>vint={new int{1},new int{2}}; or std::vector<std::shared