#include using namespace std; template class MyVector { public: T* ptr ; int capacity ; int noOfElements ; MyVector( int sizeP = 10 ) { ptr = new T[sizeP] ; capacity = sizeP ; noOfElements = 0 ; } void print() { for( int i1=0 ; i1 < noOfElements ; i1++ ) { cout << ptr[i1] << " " ; } cout << endl ; } ~MyVector() { delete[] ptr ; } void push_back( const T& obj1 ) { if ( noOfElements < capacity ) { ptr[ noOfElements ] = obj1 ; noOfElements++ ; } else { T* ptr1 = new T[ noOfElements*2 ] ; for( int i1=0 ; i1 < noOfElements ; i1++ ) { ptr1[i1] = ptr[i1] ; } // delete[] ptr ; ptr = ptr1 ; ptr[ noOfElements ] = obj1 ; noOfElements++ ; } } }; int main() { MyVector vectorObj ; vectorObj.push_back( 1 ) ; vectorObj.push_back( 2 ) ; vectorObj.print() ; MyVector vectorObj1 ; vectorObj1.push_back( "one" ) ; vectorObj1.push_back( "two" ) ; vectorObj1.print() ; }