public member function
<memory>

std::auto_ptr::operator*

X& operator*() const throw();
Dereference object
Returns a reference to the value pointed by theauto_ptrobject.

要放回的字符的auto_ptrobject must point to some object (must not be a null pointer) in order to be dereferenciable.

参数



返回值

A reference to the element pointed by theauto_ptrobject.
X isauto_ptr's template parameter (i.e., the type pointed).

示例

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

int main () {
  std::auto_ptr<int> p1 (new int (10));
  std::auto_ptr<int> p2 (new int);

  *p2 = *p1 * 2;

  std::cout << "p1 points to: " << *p1 << '\n';
  std::cout << "p2 points to: " << *p2 << '\n';

  return 0;
}

输出

p1 points to: 10
p2 points to: 20


另见