add auto_ptr.cpp
This commit is contained in:
parent
59f0145c98
commit
04851b7e5f
1 changed files with 19 additions and 0 deletions
19
auto_ptr.cpp
Normal file
19
auto_ptr.cpp
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int *i = new int;
|
||||||
|
std::auto_ptr<int> x(i);
|
||||||
|
std::auto_ptr<int> y;
|
||||||
|
/* Note: auto_ptr is deprecated. */
|
||||||
|
|
||||||
|
y = x;
|
||||||
|
|
||||||
|
std::cout << x.get() << std::endl; // Print NULL
|
||||||
|
assert(x.get() == NULL);
|
||||||
|
std::cout << y.get() << std::endl; // Print non-NULL address i
|
||||||
|
assert(y.get() != NULL);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue