zTemplate Functions and Class Templates Slides

zTemplate Functions and Class Templates Slides - 1 Template...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: 1 Template Functions and Class Templates 2010 David A. Smallberg int minimum(int a, int b) { if (a < b) return a; else return b; } double minimum(double a, double b) { if (a < b) return a; else return b; } int main() { int k; cin >> k; cout << minimum(k, 10) / 2; double x; ... double y = 3 * minimum(x*x, x+10); ... int z = minimum(0, 3*k - k + 4); ... } 2010 David A. Smallberg 2 T minimum(T a, T b) { if (a < b) return a; else return b; } 2010 David A. Smallberg template<typename T> T minimum(T a, T b) { if (a < b) return a; else return b; } int main() { int k; cin >> k; cout << minimum(k, 10) / 2; double x; ... double z = 3 * minimum(x*x, x+10); ... int z = minimum(0, 3*k - k + 4); ... } 2010 David A. Smallberg 3 template<typename T> T minimum(T a, T b) { if (a < b) return a; else return b; } int main() { int k; cin >> k; cout << minimum(k, 10) / 2; double x; ... double z = 3 * minimum(x*x, x+10); ... int z = minimum(0, 3*k - k + 4); ... } int minimum(int a, int b) { if (a < b) return a; else return b; } 2010 David A. Smallberg template<typename T> T minimum(T a, T b) { if (a < b) return a; else return b; } int main() { int k; cin >> k; cout << minimum(k, 10) / 2; double x; ... double z = 3 * minimum(x*x, x+10) ; ... int z = minimum(0, 3*k - k + 4); ... } int minimum(int a, int b) { if (a < b) return a; else return b; } double minimum(double a, double b) { if (a < b) return a; else return b; } 2010 David A. Smallberg 4 template<typename T> T minimum(T a, T b) { if (a < b) return a; else return b; } int main() { int k; cin >> k; cout << minimum(k, 10) / 2; double x; ... double z = 3 * minimum(x*x, x+10); ......
View Full Document

This note was uploaded on 04/02/2012 for the course COMPUTER S 32 taught by Professor Smallberg during the Winter '12 term at UCLA.

Page1 / 11

zTemplate Functions and Class Templates Slides - 1 Template...

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