#include using namespace std; class Copy_Counter { public: Copy_Counter(string const& n = "") : name{n}, ref_count{new int{1}}, copy_count{new int{0}} {} Copy_Counter(Copy_Counter const& rhs) : name{rhs.name}, ref_count{rhs.ref_count}, copy_count{rhs.copy_count} { ++*ref_count; ++*copy_count; } ~Copy_Counter() { if ( --*ref_count == 0 ) { cout << *copy_count << " " << name << endl; delete ref_count; delete copy_count; } } Copy_Counter& operator=(Copy_Counter const& rhs) { Copy_Counter copy{ rhs }; std::swap(copy.name, name); std::swap(copy.ref_count, ref_count); std::swap(copy.copy_count, copy_count); } void touch() {} private: string name; int* ref_count; int* copy_count; }; // NO MODIFICATIONS BELOW THIS LINE !! (when you send for correction) int main(int argc, char* argv[]) { { Copy_Counter a{}; } // Will print 0 cout << '-' << endl; { Copy_Counter a{}; for (int i{}; i < 10; ++i ) Copy_Counter loop{a}; } // Will print 10 cout << '-' << endl; { Copy_Counter a{}; Copy_Counter b{}; b = a; } // Will print 0, 1 cout << '-' << endl; { Copy_Counter c1; { Copy_Counter c2; Copy_Counter c3{c1}; Copy_Counter c4{c2}; c3 = c4; c4 = c1; c2 = c4; } // Will print 2 since c2 is copied to c4 that's copied to c3 }// Will print 3, c3 is copied to c1, c4 to c1, c2 to c4 return 0; }