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

Returns a reference to the value pointed by the auto_ptr object.

The auto_ptr object must point to some object (must not be a null pointer) in order to be dereferenciable.

Parameters

none

Return value

A reference 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
// auto_ptr::operator* example
#include <iostream>
#include <memory>
using namespace std;
int main () {
  auto_ptr<int> p1 (new int (10));
  auto_ptr<int> p2 (new int);
  *p2 = *p1 * 2;
  cout << "p1 points to: " << *p1 << "\n";
  cout << "p2 points to: " << *p2 << "\n";
  return 0;
}


Output:

p1 points to: 10
p2 points to: 20

See also