fowl.cpp 739 B

1234567891011121314151617181920212223242526
  1. // fowl.cpp -- auto_ptr a poor choice
  2. #include <iostream>
  3. #include <string>
  4. #include <memory>
  5. int main()
  6. {
  7. using namespace std;
  8. auto_ptr<string> films[5] =
  9. {
  10. auto_ptr<string> (new string("Fowl Balls")),
  11. auto_ptr<string> (new string("Duck Walks")),
  12. auto_ptr<string> (new string("Chicken Runs")),
  13. auto_ptr<string> (new string("Turkey Errors")),
  14. auto_ptr<string> (new string("Goose Eggs"))
  15. };
  16. auto_ptr<string> pwin;
  17. pwin = films[2]; // films[2] loses ownership
  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. }