C9-Templates - K thut lp trnh Phn III: Lp trnh tng qut Chng...

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

View Full Document Right Arrow Icon
K thu t l p trình Ph n III: L p trình t ng quát 0101010101010101100001 0101010101010101100001 0101010101010101100001 0101010100101010100101 0101010100101010100101 0101010100101010100101 1010011000110010010010 1010011000110010010010 1010011000110010010010 1100101100100010000010 1100101100100010000010 1100101100100010000010 0101010101010101100001 0101010101010101100001 0101010101010101100001 0101010100101010100101 0101010100101010100101 0101010100101010100101 1010011000110010010010 1010011000110010010010 1010011000110010010010 1100101100100010000010 1100101100100010000010 1100101100100010000010 0101010101010101100001 0101010101010101100001 0101010101010101100001 0101010100101010100101 0101010100101010100101 0101010100101010100101 1010011000110010010010 1010011000110010010010 1010011000110010010010 1100101100100010000010 1100101100100010000010 1100101100100010000010 y = A*x + B*u; x = C*x + d*u; StateController start() stop() LQGController start() stop() Ch ươ ng 9: Khuôn m u hàm và khuôn m ul p 12/25/2007
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 Ch ươ ng 9: Khuôn m u hàm và khuôn m ul p N idung ch ươ ng 9 9.1 Khuôn m uhàm -Vaitròc a khuôn m uhàm - Đị nh ngh ĩ a khuôn m uhàm -S d ng khuôn m uhàm 9.2 Khuôn m ul p - Đị nh ngh ĩ a khuôn m ul p -D nxu t khuôn m ul p -Víd khuôn m ul p Vector
Background image of page 2
3 Ch ươ ng 9: Khuôn m u hàm và khuôn m ul p 9.1 Khuôn m uhàm (function template) ± V n ₫ề : Nhi u hàm ch khác nhau v ki u d li u tham s áp d ng, không khác nhau v thu t toán ± Ví d : int max(int a, int b) { return (a > b)? a : b; } double max(double a, double b) { return (a > b)? a : b; } ... ± Các ví d khác: các hàm swap, sort, find, select,. .. ± B n ch t c a v n ₫ề ? N m ngôn ng l p trình còn th p, ch ư a g n v i t ư duy c a con ng ườ i! ± Gi i pháp: T ng quát hóa các hàm ch khác nhau v ki u d li u áp d ng thành khuôn m u hàm .
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 Ch ươ ng 9: Khuôn m u hàm và khuôn m ul p Đị nh ngh ĩ akhuônm uhàm ± Ví d t ng quát hóa hàm max ₫ể có th áp d ng cho nhi uki u d li u khác nhau: template <typename T > T max(T a, T b) { return (a > b)? a : b; } ± Ví d t ng quát hóa hàm swap: template <class X > X temp = a; a = b; b = temp; } ± M tkhuônm uhàminline: template <typename T> inline T max(T a, T b) { return (a > b)? a : b;} S d ng t khóa typename ho c class ₫ể khai báo tham s khuôn m u
Background image of page 4
5 Ch ươ ng 9: Khuôn m u hàm và khuôn m ul p Khai báo và s d ng khuôn m uhàm ± Ví d s d ng khuôn m uhàmmax template <class T> T max(T a, T b); template <class T> void swap(T&, T&);
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.

Page1 / 23

C9-Templates - K thut lp trnh Phn III: Lp trnh tng qut Chng...

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