Namespaces
Variants
Views
Actions

std::unique_ptr::operator*

From cppreference.com
< cpp‎ | memory‎ | unique ptr
Revision as of 15:16, 2 November 2012 by P12bot (Talk | contribs)

 
 
 
 
 

Template:ddcl list begin <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
typename std::add_lvalue_reference<T>::type operator*() const;
</td>

<td > (1) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td >
pointer operator->() const;
</td>

<td > (2) </td> <td > (since C++11) </td> </tr> Template:ddcl list end

operator* and operator-> provide access to the object owned by *this.

Contents

Parameters

(none)

Return value

1) Returns the object owned by *this, i.e. *get().

2) Returns a pointer to the object owned by *this, i.e. get().

Exceptions

1) may throw

2)
noexcept specification:  
noexcept
  

Example

#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);
}

Output:

Foo::bar
f(const Foo&)

See also

Template:cpp/memory/unique ptr/dcl list get