/****************************************************************************** *** FILE: error_message.cpp *** DATE: 03/17/2004 *** AUTHOR: Daniel Dementiev *** GOAL: This program illustrates how no litle error checking or can cause *** a damage to the data. Pay attention to the method Array::Item() *** we check that the value of the index argument is valid, but we *** just report if it's outside of the range. ******************************************************************************/ #include using namespace std; class Array { private: int count; int data[10]; int size; public: Array() : count(0), size(10) {}; int Count() const { return count; }; int Size() const { return size; }; int& Item(int index); }; int& Array::Item(int index) { if( index<0 || index>=10 ) cerr<<"Error: index is out of range in the method Array::Item(int index)\n"; return data[index]; } void main() { Array a; cout<<"count = "<