-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector.h
57 lines (46 loc) · 1.18 KB
/
vector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef _VECTOR_H
#define _VECTOR_H
/*
* The next line is used because Codewarrior has a conflict with
* the STL vector. Make sure to put the #include of this file
* AFTER all the system includes.
*/
#define vector Vector
#include <cstddef>
class ArrayIndexOutOfBounds { };
template <class Object>
class vector
{
public:
explicit vector( int theSize = 0 ) : currentSize( theSize )
{ objects = new Object[ currentSize ]; }
vector( const vector & rhs ) : objects( NULL )
{ operator=( rhs ); }
~vector( )
{ delete [ ] objects; }
int size( ) const
{ return currentSize; }
Object & operator[]( int index )
{
#ifndef NO_CHECK
if( index < 0 || index >= currentSize )
throw ArrayIndexOutOfBounds( );
#endif
return objects[ index ];
}
const Object & operator[]( int index ) const
{
#ifndef NO_CHECK
if( index < 0 || index >= currentSize )
throw ArrayIndexOutOfBounds( );
#endif
return objects[ index ];
}
const vector & operator = ( const vector & rhs );
void resize( int newSize );
private:
int currentSize;
Object * objects;
};
#include "vector.cpp"
#endif