vegnews.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // vegnews.cpp -- using new and delete with classes
  2. // compile with strngbad.cpp
  3. #include <iostream>
  4. using std::cout;
  5. #include "strngbad.h"
  6. void callme1(StringBad &); // pass by reference
  7. void callme2(StringBad); // pass by value
  8. int main()
  9. {
  10. using std::endl;
  11. {
  12. cout << "Starting an inner block.\n";
  13. StringBad headline1("Celery Stalks at Midnight");
  14. StringBad headline2("Lettuce Prey");
  15. StringBad sports("Spinach Leaves Bowl for Dollars");
  16. cout << "headline1: " << headline1 << endl;
  17. cout << "headline2: " << headline2 << endl;
  18. cout << "sports: " << sports << endl;
  19. callme1(headline1);
  20. cout << "headline1: " << headline1 << endl;
  21. callme2(headline2);
  22. cout << "headline2: " << headline2 << endl;
  23. cout << "Initialize one object to another:\n";
  24. StringBad sailor = sports;
  25. cout << "sailor: " << sailor << endl;
  26. cout << "Assign one object to another:\n";
  27. StringBad knot;
  28. knot = headline1;
  29. cout << "knot: " << knot << endl;
  30. cout << "Exiting the block.\n";
  31. }
  32. cout << "End of main()\n";
  33. // std::cin.get();
  34. return 0;
  35. }
  36. void callme1(StringBad & rsb)
  37. {
  38. cout << "String passed by reference:\n";
  39. cout << " \"" << rsb << "\"\n";
  40. }
  41. void callme2(StringBad sb)
  42. {
  43. cout << "String passed by value:\n";
  44. cout << " \"" << sb << "\"\n";
  45. }