CPP/unique ptr

From ProgrammingExamples
< CPP
Jump to: navigation, search

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)