Skip to content

Instantly share code, notes, and snippets.

@adurpas
Created December 2, 2012 18:30
Show Gist options
  • Save adurpas/4190339 to your computer and use it in GitHub Desktop.
Save adurpas/4190339 to your computer and use it in GitHub Desktop.
#2
// ISU laboratory session #9, exercise #2.
#include <iostream>
#include "SmartString.hpp"
using namespace std;
int main ()
{
// Step 1: Scope #1
{
// Step 2
SmartString ss1(new string("Hello world!"));
// Print information (ss1: string and counter that ss1 points to)
cout << endl << "[ss1]" << ss1;
// Scope #2
// After it, ss2 pops from the stack
{
// Step 3
SmartString ss2(new string("Hej verden!"));
// Print information (ss2: string and counter that ss2 points to)
cout << endl << "[ss2]" << ss2 << endl;
// Step 4
ss2 = ss1;
// Print information (ss2: string and counter that ss2 points to)
cout << endl << "[ss2]" << ss2 << endl;
// Scope #3
// ss3 is removed from the stack
{
// Copy constructor called. Assigning str and counter to what ss1 points to
SmartString ss3 = ss1;
// Print ss3
cout << endl << "[ss3]" << ss3;
// The quantity of references to str should be 3
}
// Print ss2
cout << endl << "[ss2]" << ss2;
// The quantity of references to str should be 2
}
// Print ss1
cout << endl << "[ss1]" << ss1 << endl;
// The quantity of references to str should be 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment