fowlup.cpp 780 B

1234567891011121314151617181920212223242526
  1. // fowlup.cpp -- unique_ptr not a good choice
  2. #include <iostream>
  3. #include <string>
  4. #include <memory>
  5. int main()
  6. {
  7. using namespace std;
  8. unique_ptr<string> films[5] =
  9. {
  10. unique_ptr<string> (new string("Fowl Balls")),
  11. unique_ptr<string> (new string("Duck Walks")),
  12. unique_ptr<string> (new string("Chicken Runs")),
  13. unique_ptr<string> (new string("Turkey Errors")),
  14. unique_ptr<string> (new string("Goose Eggs"))
  15. };
  16. unique_ptr<string> pwin;
  17. pwin = films[2]; // films[2], pwin both point to "Chicken Runs"
  18. cout << "The nominees for best avian baseball film are\n";
  19. for (int i = 0; i < 5; i++)
  20. cout << *films[i] << endl;
  21. cout << "The winner is " << *pwin << "!\n";
  22. // cin.get();
  23. return 0;
  24. }