L27templates

L27templates - Templates a way of writing generic code...

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

View Full Document Right Arrow Icon
Templates a way of writing generic code
Background image of page 1

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

View Full DocumentRight Arrow Icon
Questions about Templates what is a template? why are templates needed? how is a function template declared? what does this function prototype mean: template<class T> void myfunc(int*,const T&, T*); how does the compiler figure out what class/type to substitute for the template parameter? how is templated function invoked? is template an executable statement?
Background image of page 2
Why Templates certain code operates similarly regardless of type example: swapping two values templates parameterize type and allow writing generic code
Background image of page 3

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

View Full DocumentRight Arrow Icon
Standalone Function Templates function head/prototype are preceded by template <class typeParameter > style convention – always put on separate line example template <class T> void print_stuff(int a, T b, T c); type parameter may be passed by reference/returned/declared constant template <class T> void show_stuff(int, T&, const T&); in definition template <class T> void show_stuff(int a, T& b, const T& c){ cout << a << b << c; }
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.

This note was uploaded on 04/22/2010 for the course CS 23021 taught by Professor Staff during the Spring '08 term at Kent State.

Page1 / 8

L27templates - Templates a way of writing generic code...

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