template <class Etype>
class BoundedVector : public Vector<Etype>
{
public:
BoundedVector( int L, int H ) :
Vector<Etype>( H - L + 1 ), Low ( L ) { }
const Etype & operator[] ( int Index ) const;
Etype & operator[] ( int Index );
private:
int Low;
};
template <class Etype>
Etype &
BoundedVector<Etype>::operator [ ] ( int Index )
{
return Vector<Etype>::operator[ ] ( Index - Low );
}
template <class Etype>
const Etype &
BoundedVector<Etype>::operator [ ] ( int Index ) const
{
return Vector<Etype>::operator[ ] ( Index - Low );
}
main( )
{
BoundedVector<double> V( 20, 39 );
BoundedVector<double> W( 20, 39 );
int i;
for( i = 20; i < 40; i++)
cout << V[ i ] << " ";
cout << endl;
for( i = 20; i < 40; i++ )
V[ i ] = i;
for( i = 20; i < 40; i++)
cout << V[ i ] << " ";
cout << endl;
V.Double( );
cout << V[50];
cout << V[70];
return 0;
}