Skip to content

Instantly share code, notes, and snippets.

@jitpaul
Created April 26, 2018 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jitpaul/b6915128865a350dc9aad43be96f94a8 to your computer and use it in GitHub Desktop.
Save jitpaul/b6915128865a350dc9aad43be96f94a8 to your computer and use it in GitHub Desktop.
Smart Pointers
#include <memory>
#include <iostream>
using namespace std;
int main(){
shared_ptr<int> a(new int(4)); //correct
{
shared_ptr<int> b = a; //correct.
std::cout<<*b<<std::endl; //correct.
}
std::cout<<*a<<std::endl; //correct. 'a' still valid although 'b' went out of scope.
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment