如何将唯一_PTR参数传递给构造函数或函数?
unique_ptr
#include <memory>class Base{ public: typedef unique_ptr<Base> UPtr; Base(){} Base(Base::UPtr n):next(std::move(n)){} virtual ~Base(){} void setNext(Base::UPtr n) { next = std::move(n); } protected : Base::UPtr next;};
unique_ptr
std::move
Base::UPtr b1;Base::UPtr b2(new Base());b1->setNext(b2); //should I write b1->setNext(std::move(b2)); instead?
杨__羊羊
ITMISS
相关分类