// Ch. 13 Demo Program #5
// Mr. Minich
// Purpose - to demonstrate the use of const with reference parameters.
// YOU MUST DELETE THE CONST KEYWORDS IN ORDER TO SUCCESSFULLY COMPILE &
// EXECUTE THIS PROGRAM
#include <iostream.h>
void display1(int &); // used to demonstrate danger of not protecting
// reference parameters with use of const
void display2( const int &); // used to demonstrate the caution of using const
// reference parameters
int main()
{
int value = 5; // used to demonstrate use of const reference
// parameters
cout << "Initially, value is:\t" << value << endl;
display1(value);
cout << "After display1 is called, value is:\t" << value << endl;
display2(value);
cout << "After display2 is called, value is:\t" << value << endl << endl;
return 0;
}// end of main
void display1(int & incoming)
{
incoming = 7;
}// end of display1
void display2( const int & incoming)
// const is to be used in front of a parameter if you do not intend to modify the
// value of its corresponding argument in the calling function. This example is
// trivial since we are purposefully changing the value of incoming (i.e. value)
// in order to demonstrate how the use of const will result in a compiler error
{
incoming = 8; // compiler error message: l-value specifies const object
}// end of display1