public member function
<memory>

std::shared_ptr::operator*

element_type& operator*() const noexcept;
Dereference object
Returns a reference to the object pointed by the stored pointer.

It is equivalent to: *get().

If shared_ptr's template parameter is void, it is platform- and compiler-dependent whether this member function is defined, and which is its return type in that case.

Parameters

none

Return value

A reference to the object pointed.
element_type is a member type, defined as an alias of shared_ptr's template parameter.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// shared_ptr::operator*
#include <iostream>
#include <memory>

int main () {
  std::shared_ptr<int> foo (new int);
  std::shared_ptr<int> bar (new int (100));

  *foo = *bar * 2;

  std::cout << "foo: " << *foo << '\n';
  std::cout << "bar: " << *bar << '\n';

  return 0;
}


Output:
foo: 200
bar: 100

See also