home *** CD-ROM | disk | FTP | other *** search
- // ex06007.cpp
- // Call by reference
- #include <iostream.h>
-
- // ------ simple date class
- struct date {
- int da, mo, yr;
- void display(void);
- };
- void date::display()
- {
- cout << da << '/' << mo << '/' << yr;
- }
- void swapper(date&, date&);
- void display(date&, date&);
-
- main()
- {
- date now = {23,2,90}; // two dates
- date then = {10,9,60};
-
- display(now, then); // display the dates
- swapper(now, then); // swap them
- display(now, then); // display them swapped
- }
-
- // ----- this function swaps the caller's dates
- void swapper(date& dt1, date& dt2)
- {
- date save;
- save = dt1;
- dt1 = dt2;
- dt2 = save;
- }
-
- void display(date& now, date& then)
- {
- cout << "\n Now: ";
- now.display();
- cout << "\n Then: ";
- then.display();
- }