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 isvoid, it is platform- and compiler-dependent whether this member function is defined, and which is its return type in that case.

参数



返回值

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

示例

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

输出
foo: 200
bar: 100


另见