Sams Teach Yourself C++ in 21 Days

(singke) #1
70:
71: return pType[0]; // appease MFC
72: }
73:
74: int main()
75: {
76: try
77: {
78: Array intArray(0);
79: for (int j = 0; j < 100; j++)
80: {
81: intArray[j] = j;
82: cout << “intArray[“ << j << “] okay...” << endl;
83: }
84: }
85: catch (Array::xBoundary)
86: {
87: cout << “Unable to process your input!” << endl;
88: }
89: catch (Array::xTooBig)
90: {
91: cout << “This array is too big...” << endl;
92: }
93:
94: catch (Array::xTooSmall)
95: {
96: cout << “This array is too small...” << endl;
97: }
98: catch (Array::xZero)
99: {
100: cout << “You asked for an array”;
101: cout << “ of zero objects!” << endl;
102: }
103: catch (...)
104: {
105: cout << “Something went wrong!” << endl;
106: }
107: cout << “Done.” << endl;
108: return 0;
109: }

This array is too small...
Done.
The significant change is on lines 27–30, where the class hierarchy is estab-
lished. Classes xTooBig,xTooSmall, and xNegativeare derived from xSize, and
xZerois derived from xTooSmall.

OUTPUT


734 Day 20


LISTING20.6 continued

ANALYSIS
Free download pdf