Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
Miscellaneous
complex
exception
functional
iterator
limits
locale
memory
new
numeric
stdexcept
typeinfo
utility
valarray
memory
classes:
allocator
auto_ptr
auto_ptr_ref
raw_storage_iterator
functions:
get_temporary_buffer
return_temporary_buffer
uninitialized_copy
uninitialized_fill
uninitialized_fill_n
auto_ptr
auto_ptr::auto_ptr
auto_ptr::~auto_ptr
member functions:
auto_ptr::get
auto_ptr::operator*
auto_ptr::operator->
auto_ptr::operator=
auto_ptr::operator
auto_ptr::release
auto_ptr::reset


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