小编J W*_*J W的帖子

有没有更好的方法添加两个智能指针?

我为自写类重载了operator +,并通过智能指针处理了这些类的实例。现在,我想知道是否没有更好的方法来利用运算符。此外,我不知道如何将它们重新打包到shared_ptr中。

class A
{
  A operator + (A const & other)
  { //do some addition stuff and return new A}
};

std::shared_ptr<A> a, b;

//Currently I add them up like this
auto c = *a.get() + *b.get()



Run Code Online (Sandbox Code Playgroud)

c++ smart-pointers operator-overloading

2
推荐指数
1
解决办法
85
查看次数

标签 统计

c++ ×1

operator-overloading ×1

smart-pointers ×1