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

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -