auto_ptr::operator->


public member function
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 <memory>
using namespace std;

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

  auto_ptr<mypair> p (new mypair);

  *p = 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++)
      cout << p->first[i] << " ";

    cout << endl;
  }

  return_temporary_buffer (p->first);

  return 0;
}


Output:

0 5 10 15 20


See also