Skip to content

Instantly share code, notes, and snippets.

@adurpas
Created December 2, 2012 18:31
Show Gist options
  • Save adurpas/4190341 to your computer and use it in GitHub Desktop.
Save adurpas/4190341 to your computer and use it in GitHub Desktop.
#4.1
// ISU laboratory session #9, exercise #4-1.
#include <iostream>
#include <string>
#include <boost/shared_ptr.hpp>
using namespace std;
int main()
{
{
boost::shared_ptr<string> ss1(new string("Hello world!"));
boost::shared_ptr<string> ss2(new string("Hej verden!"));
cout << "ss1: " << ss1.use_count() << endl;
cout << "ss2: " << ss2.use_count() << endl << endl;
cout << "Assign ss2 = ss1" << endl;
ss1 = ss2;
cout << "ss1: " << ss1.use_count() << endl;
cout << "ss2: " << ss2.use_count() << endl << endl;
{ // New scope
cout << "New scope" << endl;
boost::shared_ptr<string> ss3 = ss1;
cout << "ss3: " << ss3.use_count() << endl;
}
cout << "End of the new scope" << endl << endl;
cout << "ss2: " << ss2.use_count() << endl << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment