Sams Teach Yourself C++ in 21 Days

(singke) #1
Exploiting References 273

9


22: }
23:
24: SimpleCat::~SimpleCat()
25: {
26: cout << “Simple Cat Destructor...” << endl;
27: }
28:
29: SimpleCat FunctionOne (SimpleCat theCat);
30: SimpleCat* FunctionTwo (SimpleCat *theCat);
31:
32: int main()
33: {
34: cout << “Making a cat...” << endl;
35: SimpleCat Frisky;
36: cout << “Calling FunctionOne...” << endl;
37: FunctionOne(Frisky);
38: cout << “Calling FunctionTwo...” << endl;
39: FunctionTwo(&Frisky);
40: return 0;
41: }
42:
43: // FunctionOne, passes by value
44: SimpleCat FunctionOne(SimpleCat theCat)
45: {
46: cout << “Function One. Returning... “ << endl;
47: return theCat;
48: }
49:
50: // functionTwo, passes by reference
51: SimpleCat* FunctionTwo (SimpleCat *theCat)
52: {
53: cout << “Function Two. Returning... “ << endl;
54: return theCat;
55: }

Making a cat...
Simple Cat Constructor...
Calling FunctionOne...
Simple Cat Copy Constructor...
Function One. Returning...
Simple Cat Copy Constructor...
Simple Cat Destructor...
Simple Cat Destructor...
Calling FunctionTwo...
Function Two. Returning...
Simple Cat Destructor...

OUTPUT


LISTING9.10 continued

Free download pdf