Skip to content

Instantly share code, notes, and snippets.

@jitpaul
Created Apr 26, 2018
Embed
What would you like to do?
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