c++ - Shared data class using std::shared_ptr -
i need class implements shared data semantics, , std::shared_ptr
place start. think typical implementation of such class use private shared_ptr
shared data, , implement @ least copy constructor , operator=
.
something like:
class shareddataclass { public: shareddataclass(const shareddataclass& other) { data_ = other.data_; }; shareddataclass& operator=(const shareddataclass& other) { data_ = other.data_; return *this; } private: std::shared_ptr<datatype> data_; };
i'd ask if has criticism offer on above implementation. there other member/operator should implemented consistency?
there no need implement copy constructor or assignment operator in case. let compiler defines trivial default ones you, shared_ptr job expecting.
Comments
Post a Comment