public member function
<memory>

std::auto_ptr::operator->

X* operator->() const throw();
Dereference object member
Returns the element pointed by the auto_ptr object in order to access one of its members.

Parameters

none

Return value

A pointer to the element pointed by the auto_ptr object.
X is auto_ptr's template parameter (i.e., the type pointed).

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// auto_ptr::operator-> example
#include <iostream>
#include <cstddef>
#include <memory>

int main () {
  typedef std::pair<int*,std::ptrdiff_t> mypair;

  std::auto_ptr<mypair> p (new mypair);

  *p = std::get_temporary_buffer<int>(5);

  if (p->second >= 5) {
    for (int i=0; i<5; i++)
      p->first[i]=i*5;

    for (int i=0; i<5; i++)
      std::cout << p->first[i] << " ";

    std::cout << '\n';
  }

  std::return_temporary_buffer (p->first);

  return 0;
}


Output:

0 5 10 15 20

See also