// class templates #include using namespace std; /*A conatiner to hold different kinds of objects.*/ template class container { T* ptr ; int capacity = 10 ; int currentSize = 0 ; public: container () { ptr = new T[10] ; } void add( T obj1 ) { if ( currentSize >= 10 ) { cout << "Reached capacity." << endl ; return ; } ptr[ currentSize++ ] = obj1 ; } T get( int index ) { if ( index >= currentSize ) { cout << "Invalid index." << endl ; } else return ptr[ currentSize-1 ] ; } }; int main () { container object1 ; container object2 ; object1.add( 10 ) ; cout << object1.get(0) << endl ; object2.add( "James" ) ; cout << object2.get(0) << endl ; return 0; }