{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture-18 - C Class Templates Object Oriented Programming...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Object Oriented Programming C++ Class Templates R.B. Lenin Winter 2006 DA-IICT C++ Class Templates
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2 Object Oriented Programming C++ Class Templates R.B. Lenin Winter 2006 DA-IICT Introduction • Templates Easily create a large range of related functions or classes Function template - the blueprint of the related functions Template function - a specific function made from a function template
Background image of page 2
3 Object Oriented Programming C++ Class Templates R.B. Lenin Winter 2006 DA-IICT Class Templates Class templates Allow type-specific versions of generic classes • Format: template <class T> class ClassName { definition } Need not use "T" , any identifier will work
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
4 Object Oriented Programming C++ Class Templates R.B. Lenin Winter 2006 DA-IICT Class Templates When nonprimitive data types are used in a Class template, there are two constraints: a default constructor must be defined must support the assignment operator if an object of a template class contains dynamically allocated memory, the assignment operator should be overloaded for that type To create an object of the class, type ClassName < type > myObject; Example: Stack< double > doubleStack;
Background image of page 4
5 Object Oriented Programming C++ Class Templates R.B. Lenin Winter 2006 DA-IICT Class Templates (II) Template class member functions Declared normally, but preceded by template<class T>
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}