std::unique_ptr<T,Deleter>::operator*
提供: cppreference.com
<tbody>
</tbody>
typename std::add_lvalue_reference<T>::type operator*() const; |
(1) | (C++11以上) |
pointer operator->() const noexcept; |
(2) | (C++11以上) |
operator* および operator-> は *this が所有するオブジェクトへのアクセスを提供します。
get() == nullptr の場合、動作は未定義です。
引数
(なし)
戻り値
1) *this の所有するオブジェクトを返します。 *get() と同等です。
2) *this の所有するオブジェクトを返します。 get() と同等です。
例外
1) pointer が例外を投げる operator* を定義している場合、例外を投げるかもしれません。
例
Run this code
#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&)
関連項目
| 管理対象オブジェクトへのポインタを返します (パブリックメンバ関数) |