iFr*_*cht 1 c++ stl smart-pointers operators c++11
做std::shared_ptr和std::unique_ptr功能.get()和operator->做的完全一样吗?
或者与std::vectors .at()和operator[]?有区别吗?
具有相同的行为(在两种情况下operator->()都定义为返回get()),但operator->()具有get()必须不返回0 的前提条件.
这意味着:
a.get(); // does not cause UB just because holds a null pointer
a.operator->(); // would cause UB if a.get() == 0
Run Code Online (Sandbox Code Playgroud)
哪里a是a std::unique_ptr或a std::shared_ptr.