Created
December 2, 2012 18:31
-
-
Save adurpas/4190341 to your computer and use it in GitHub Desktop.
#4.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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