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 DocumentRight 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 •F o r m a t : 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 DocumentRight 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> • Generic data in class listed as type
Background image of page 5

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

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

This note was uploaded on 09/15/2010 for the course CSE IT325 taught by Professor Maniklaldas during the Spring '09 term at Punjab Engineering College.

Page1 / 20

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

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online