C++ Codes
Algorithms
Algorithm Analysis in C++
Beginners
Code Snippets
Graphics
Data Structures
File Manipulation
Games
Mathematics
Miscellaneous
Visual C++ Library
C++ > Data Structures and Algorithm Analysis in C++ sample source codes
vector.cpp - If you don't have a vector type
vector.cpp - If you don't have a vector type #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 ) { #ifdef WIN32 if( currentSize != 0 ) #endif 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 ]; for( int k = 0; k < numToCopy; k++ ) objects[ k ] = oldArray[ k ]; #ifdef WIN32 if( currentSize != 0 ) #endif delete [ ] oldArray; currentSize = newSize; } #endif
Privacy Policy
|
Link to Us
|
Links