Difference between revisions of "CPP/unique ptr"
From ProgrammingExamples
< CPP
Daviddoria (Talk | contribs) (Created page with '==auto_ptr.cpp== <source lang="cpp"> #include <iostream> #include <memory> int main(int argc, char *argv[]) { std::auto_ptr<int> myInt(new int); *myInt = 5; std::cout <…') |
Daviddoria (Talk | contribs) |
||
| (3 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
| − | == | + | If you see 'auto_ptr' in code, it is simply the old version (deprecated) of unique_ptr shown in this example. |
| + | |||
| + | ==unique_ptr.cpp== | ||
<source lang="cpp"> | <source lang="cpp"> | ||
#include <iostream> | #include <iostream> | ||
| Line 8: | Line 10: | ||
{ | { | ||
| − | std:: | + | std::unique_ptr<int> myInt(new int); |
*myInt = 5; | *myInt = 5; | ||
| Line 21: | Line 23: | ||
cmake_minimum_required(VERSION 2.6) | cmake_minimum_required(VERSION 2.6) | ||
| − | PROJECT( | + | PROJECT(unique_ptr) |
| − | ADD_EXECUTABLE( | + | ADD_EXECUTABLE(unique_ptr unique_ptr.cpp) |
</source> | </source> | ||
Latest revision as of 09:23, 6 April 2011
If you see 'auto_ptr' in code, it is simply the old version (deprecated) of unique_ptr shown in this example.
unique_ptr.cpp
#include <iostream> #include <memory> int main(int argc, char *argv[]) { std::unique_ptr<int> myInt(new int); *myInt = 5; std::cout << *myInt << std::endl; return 0; }
CMakeLists.txt
cmake_minimum_required(VERSION 2.6) PROJECT(unique_ptr) ADD_EXECUTABLE(unique_ptr unique_ptr.cpp)