Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CSE 2341 Object Oriented Programming with C++ Note Set #17.

Similar presentations


Presentation on theme: "1 CSE 2341 Object Oriented Programming with C++ Note Set #17."— Presentation transcript:

1 1 CSE 2341 Object Oriented Programming with C++ Note Set #17

2 2 Overview Templates –Class templates

3 3 Class Templates Templates can be used to create generic ADTs. Can create one general version of class w/o having to duplicate for different data types Template prefix placed before class declaration

4 4 SimpleVector template class SimpleVector { private: T* aptr; int arraySize; void memError(); void subError(); public: SimpleVector() {aptr = 0; arraySize = 0;} SimpleVector(int); SimpleVector(const SimpleVector&); ~SimpleVector(); int size() {return arraySize;} t& operator[](const int&); } SimpleVector.h Complete Definition in Handout

5 5 Defining Objects of the Class Template Data type that is to be passed as the type parameter is placed in angle brackets after the class name as in: SimpleVector intTable(10); SimpleVector doubleTable(10)

6 6 Templates and Inheritance Templated classes can be involved in inheritance template class SearchableVector:public SimpleVector { public: SearchableVector(int s):SimpleVector (s) {} SearchableVector(SearchableVector&); SearchableVector(SimpleVector & obj): SimpleVector (obj) {} int findItem(T); };

7 7 Fini ?


Download ppt "1 CSE 2341 Object Oriented Programming with C++ Note Set #17."

Similar presentations


Ads by Google