-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.cpp
More file actions
35 lines (28 loc) · 774 Bytes
/
vector.cpp
File metadata and controls
35 lines (28 loc) · 774 Bytes
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
#ifndef _VECTOR_CPP_
#define _VECTOR_CPP_
#include "vector.h"
template <class Object>
const vector<Object> & vector<Object>::operator=( const vector<Object> & rhs )
{
if( this != &rhs )
{
delete [ ] objects;
currentSize = rhs.size( );
objects = new Object[ currentSize ];
for( int k = 0; k < currentSize; k++ )
objects[ k ] = rhs.objects[ k ];
}
return *this;
}
template <class Object>
void vector<Object>::resize( int newSize )
{
Object *oldArray = objects;
int numToCopy = newSize < currentSize ? newSize : currentSize;
objects = new Object[ newSize ];
currentSize = newSize;
for( int k = 0; k < numToCopy; k++ )
objects[ k ] = oldArray[ k ];
delete [ ] oldArray;
}
#endif