I need a class that implements shared data semantics, and probably std::shared_ptr is a good place to start. I think a typical implementation of such class could use an private shared_ptr to the shared data, and then implement at least copy constructor and 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 like to ask if anyone has some criticism to offer on the above implementation. Is there any other member/operator that should be implemented for consistency?
= default;seems enoughstd::shared_ptr<DataType> datatakes care of all this for you.defaultis all you really need in this case. I guess c++11 is succeeding in making things easier at last...