#include #include #include #include "BalloonT.h" using namespace std; void PrintBalloon(const shared_ptr & b); void ChangeBalloon(shared_ptr param); int main() { // this will not work, no default constructor //BalloonT x; shared_ptr a, b, c; a = make_shared(ColorT::RED); b = a; a->Value(7); cout << "The original and the copy " << endl; PrintBalloon(a); PrintBalloon(b); c = make_shared(ColorT::GREEN, 4); a = b = c; cout << endl << endl; cout << "The three new copies " << endl; PrintBalloon(c); PrintBalloon(b); PrintBalloon(a); a->Pop(); cout << endl << endl; cout << "The three values after a is popped " << endl; PrintBalloon(a); PrintBalloon(b); PrintBalloon(c); ChangeBalloon(a); cout << endl << endl; cout << "The values after ChangeBalloon(a) " << endl; PrintBalloon(a); PrintBalloon(b); PrintBalloon(c); cout << endl; { // declare an instance that will go out of scope auto d = a; PrintBalloon(d); } PrintBalloon(a); vector> balloons; cout << endl; cout << "Building a list of balloons " << endl; for(ColorT i =ColorT::RED; i < ColorT::NO_COLOR; i++) { cout << "making a a " << i << " balloon" << endl; auto tmp = make_shared(i, rand()%8+3); balloons.push_back(tmp); } cout << endl; cout << "The original list of balloons " << endl; for(auto x: balloons) { PrintBalloon(x); } for (auto x: balloons) { x->Value(x->Value()+rand()%3); } cout << endl << endl; cout << "The modified list of balloons " << endl; for(auto x: balloons) { PrintBalloon(x); } return 0; } void PrintBalloon(const shared_ptr & b){ if (b != nullptr) { cout << "A balloon of " << b->Color() << " is worth " << b->Value() << endl; } } void ChangeBalloon(shared_ptr param){ // pass by pointer if (param != nullptr) { param->Value(10'000); } }