#include #include #include struct OtherClass { OtherClass() = default; ~OtherClass() = default; OtherClass(const OtherClass&) = delete; OtherClass& operator=(const OtherClass&) = delete; OtherClass(OtherClass&&) = default; OtherClass& operator=(OtherClass&&) = default; }; struct Buf { static std::shared_ptr Create(size_t count, const std::shared_ptr*& others) { return std::make_shared(count, others); } static std::shared_ptr Create(size_t count, std::shared_ptr*&& others) { return std::make_shared(count, std::move(others)); } Buf(size_t count, const std::shared_ptr*& other) { others.reserve(count); for(size_t i = 0; i < count; ++i) { others.push_back(other[i]); } } Buf(size_t count, std::shared_ptr*&& other) { others.reserve(count); for(size_t i = 0; i < count; ++i) { others.push_back(std::move(other[i])); } } Buf() = default; ~Buf() = default; Buf(const Buf&) = delete; Buf& operator=(const Buf&) = delete; Buf(Buf&&) = default; Buf& operator=(Buf&&) = default; std::vector> others; }; std::shared_ptr buf; int main() { std::shared_ptr other; //this calls Buf(size_t count, std::shared_ptr*&& other) //instead of //Buf(size_t count, const std::shared_ptr*& other) //why? buf = Buf::Create(1, &other); //and this is ok, Buf(size_t count, std::shared_ptr*&& other), because of std::move() std::shared_ptr other; buf = Buf::Create(1, std::move(&other)); }