#include // Excecoes da classe Vector struct VectorError {}; struct VectorBadIndex : public VectorError { int index; VectorBadIndex( int i ) { index = i; } }; struct VectorBadAlloc : public VectorError {}; // Definicao da classe template class Vector { T *elems; int size; public: Vector(int s) throw ( VectorBadAlloc ); T& operator[](int i) throw( VectorBadIndex ); }; template Vector::Vector(int s) throw ( VectorBadAlloc ) { size=s; elems = new T[size]; if (!elems) throw VectorBadAlloc(); } template T& Vector::operator[](int i) throw( VectorBadIndex ) { if (i>=0 && i a(10); Vector ac(1000); for (int i=0; i<3000; i++) { a [i] = i; ac[i] = "abc"; } } catch ( VectorBadIndex i ) { printf("Invalid index: %d \n ", i.index ); } catch ( VectorBadAlloc ) { printf("Out of memory \n " ); } catch (...) { printf("Unexpected error. \n " ); } return 0; }