我为自写类重载了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)