templates 2 - Templates Why Templates? The transposition of...

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

View Full Document Right Arrow Icon
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
Templates 2 Why Templates? The transposition of one closely related set of concepts, which are applied to one kind of object, to another kind of object, is usual practice in human thought. What is captured in the mind is the concept itself, and it is applied to various objects to produce an appropriate application. For example…consider the concept of a list. We talk of lists of students, lists of cars, lists of videos, etc. The concept is the same…it is a collection of objects .
Background image of page 2
Templates 3 What are Templates? Templates are data type generators. Templates are function generators. Definitions A class template defines the layout and operations for an unbounded set of related types A function template defines an unbounded set of related functions…a family of functions
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 Without Templates Consider the following implementation of a vector data structure: class Vector{ public: void store(int index, void* data); void* retrieve(int index); void* operator[](int index); private: void** _data; }; ... int main() {
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 13

templates 2 - Templates Why Templates? The transposition of...

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

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