Templates
Në shqip: Shabllonet (templates)
ShpjegimiSQ
Templates të lejojnë të shkruash një funksion ose klasë një herë, që punon me çdo tip — int, double, string. vector<int> dhe vector<string> janë i njëjti template me tipe të ndryshme. Janë si generics-at e Java-s.
EnglishEN
Templates let you write a function or class once that works with any type — int, double, string. vector<int> and vector<string> are the same template with different types. They're like Java's generics.
Si ta mendosh
Si kallëpi i biskotave: i njëjti kallëp, por mund ta mbushësh me brumë çokollate, vanilje ose kanelle.
Lexoje në anglisht
Like a cookie cutter: the same cutter, but you can use chocolate, vanilla or cinnamon dough.
Shembull kodicpp
template <typename T>
T maksimumi(T a, T b) { return a > b ? a : b; }
maksimumi(3, 7); // 7
maksimumi(2.5, 1.5); // 2.5