C++ .get()和->;之间有区别吗;用智能指针?

C++ .get()和->;之间有区别吗;用智能指针?,c++,c++11,stl,operators,smart-pointers,C++,C++11,Stl,Operators,Smart Pointers,std::shared_ptr和std::unique_ptrs函数.get()和操作符->是否完全相同 或者与std::vectors.at()和操作符[]有区别吗?具有相同的行为(在这两种情况下操作符->()被定义为返回get()),但是操作符->()有一个先决条件,即get()不能返回0 这意味着: a.get(); // does not cause UB just because holds a null pointer a.operator->(); // wou

std::shared_ptr
std::unique_ptr
s函数
.get()
操作符->
是否完全相同


或者与
std::vector
s
.at()
操作符[]
有区别吗?

具有相同的行为(在这两种情况下
操作符->()
被定义为返回
get()
),但是
操作符->()
有一个先决条件,即
get()
不能返回0

这意味着:

a.get();        // does not cause UB just because holds a null pointer
a.operator->(); // would cause UB if a.get() == 0

其中
a
std::unique_ptr
std::shared_ptr
具有相同的行为(在这两种情况下
操作符->()
被定义为返回
get()
),但
操作符->()
具有的前提条件是
get()
不能返回0

这意味着:

a.get();        // does not cause UB just because holds a null pointer
a.operator->(); // would cause UB if a.get() == 0
其中
a
std::unique\u ptr
std::shared\u ptr