std::unique_ptr::operator*
typename std::add_lvalue_reference<T>::type operator*() const; | (1) | (since C++11) |
---|---|---|
pointer operator->() const; | (2) | (since C++11) |
operator*
和operator->
提供对*this
...
如果get() == nullptr
...
参数
%280%29
返回值
1%29返回由*this
,相当于*get()
...
2%29返回指向*this
,即.get()
...
例外
1%5月29日投掷,例如pointer
定义抛出operator*
2%29。
noexcept
规格:
noexcept
例
二次
#include <iostream>
#include <memory>
struct Foo {
void bar() { std::cout << "Foo::bar\n"; }
};
void f(const Foo& foo)
{
std::cout << "f(const Foo&)\n";
}
int main()
{
std::unique_ptr<Foo> ptr(new Foo);
ptr->bar();
f(*ptr);
}
二次
产出:
二次
Foo::bar
f(const Foo&)
二次
另见
get | returns a pointer to the managed object (public member function) |
---|
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com