Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
Main Page
Related Pages
Topics
Namespaces
Data Structures
Files
File List
Globals
EXTERNAL_HEADERS
RSL
examples
manual
auto_ptr.cpp
Go to the documentation of this file.
1
29
#include <iostream>
// for cout, endl
30
#include <memory>
// for auto_ptr
31
32
#include <
examples.h
>
33
34
35
// A simple structure.
36
class
X
37
{
38
int
i_
;
39
40
public
:
41
42
X
(
int
i
) :
i_
(
i
) {
43
std::cout <<
"X::X ("
<<
i_
<<
')'
<< std::endl;
44
}
45
46
~X
() {
47
std::cout <<
"X::~X ["
<<
i_
<<
']'
<< std::endl;
48
}
49
50
int
get
()
const
{
return
i_
; }
51
};
52
53
54
int
main
()
55
{
56
// a implicitly initialized to 0 (the null pointer)
57
std::auto_ptr<X>
a
;
58
59
// Establish a scope.
60
if
(1) {
61
// b will hold a pointer to an X.
62
std::auto_ptr<X>
b
(
new
X
(12345));
63
64
// a will now be the owner of the underlying pointer.
65
a
=
b
;
66
}
67
68
std::cout <<
"b destroyed"
<< std::endl;
69
70
// Output the value contained by the underlying pointer.
71
#ifndef _RWSTD_NO_NONCLASS_ARROW_RETURN
72
std::cout <<
a
->get () << std::endl;
73
#else
74
std::cout << (*a).get () << std::endl;
75
#endif
76
77
// The pointer will be delete'd when a is destroyed on leaving scope.
78
return
0;
79
}
i
#define i
Definition
17.names.cpp:126
i_
#define i_
Definition
17.names.cpp:180
a
#define a
Definition
17.names.cpp:109
b
#define b
Definition
17.names.cpp:110
main
int main()
Definition
auto_ptr.cpp:54
examples.h
X
Definition
DUMMY_DEFAULT_ARG.cpp:35
X::get
int get() const
Definition
auto_ptr.cpp:50
X::~X
~X()
Definition
auto_ptr.cpp:46
X::X
X(int i)
Definition
auto_ptr.cpp:42
Generated by
1.9.8