1: // Filename: TESTREM4.CPP
2: // Purpose: Tests copy constructor in three different situations
4: #include <iostream>
5: using namespace std;
7: #include "REM4.H"
8: #include "PAUSE.H"
10: void DisplayReminderWithBanner(Reminder r)
11: // Pre: "r" is initialized
12: // Post: "r" is displayed as before, but with *'s above and ='s below.
13: {
14: cout << "*****************************************" << endl;
15: r.Display(); cout << endl;
16: cout << "=========================================" << endl;
17: }
19: Reminder Halloween()
20: // Pre: none
21: // Post: A date of October 31, 2000, with message "Boo!" is returned.
22: {
23: Reminder r(20001031, "Boo!");
24: return r;
25: }
27: int main()
28: {
29: cout << endl;
31: Reminder r(20000315, "Ides of March");
32: r.Display(); cout << endl; Pause(0);
34: Reminder r1;
35: // Overloaded assignment operator = invoked here because
36: // object r is being assigned to object r1:
37: r1 = r;
38: r1.Display(); cout << endl; Pause(0);
40: // Copy constructor invoked here because object r2
41: // is being initialized with a copy of r:
42: Reminder r2 = r;
43: r2.Display(); cout << endl; Pause(0);
45: // Copy constructor invoked here because (once again)
46: // an object r3 is being initialized with a copy of r:
47: Reminder r3(r);
48: r3.Display(); cout << endl; Pause(0);
50: // Copy constructor invoked here because object r3 is being
51: // passed by value to the formal parameter r of DisplayReminderWithBanner:
52: DisplayReminderWithBanner(r3); cout << endl; Pause(0);
54: // Copy constructor invoked here because r is a local object
55: // in the body of the Halloween function and is being returned:
56: Halloween().Display(); cout << endl; Pause(0);
58: return 0;
59: }