共有データセマンティクスを実装するクラスが必要です。おそらく、std::shared_ptr
を開始するのがよいでしょう。私はそのようなクラスの典型的な実装は、共有データにプライベートshared_ptr
を使用し、少なくともコピーコンストラクタとoperator=
を実装できると思います。私は誰もが上記の実装に提供するためにいくつかの批判があればお願いしたいと思いstd :: shared_ptrを使用した共有データクラス
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_;
};
:よう
何か。一貫性のために実装すべき他のメンバー/演算子はありますか?
'=デフォルト;'は十分だと思われます – Jarod42
'std :: shared_ptr data'がこれをすべて処理します。 –
また、移動コンストラクタ/割り当てもあります。 – Jarod42