Breymann. C++ Einführung und professionelle Programmierung

Breymann. C++ Einführung und professionelle Programmierung Breymann. C++ Einführung und professionelle Programmierung

vred.bioinf.uni.sb.de
von vred.bioinf.uni.sb.de Mehr von diesem Publisher
17.11.2014 Aufrufe

4.4 Funktions-Templates templates == parametrisierte Datentypen template Funktionsdefinition Beispiel: Quicksort: #include #include using namespace std; // Templates mit T als Parameter für den Datentyp (Platzhalter) template void tausche(T &a, T &b) { // a und b vertauschen const T temp = a; a = b; b = temp; } Breymann C++, c○ Hanser Verlag München Inhalt ◭◭ ◭ ◮ ◮◮ 136 zurück Ende

template int kleiner(const T& a, const T& b) { return (a < b); } // Vergleich template void drucke(const vector& V) { for(size_t i = 0; i < V.size(); ++i) cout

4.4 Funktions-Templates<br />

templates == parametrisierte Datentypen<br />

template Funktionsdefinition<br />

Beispiel: Quicksort:<br />

#include<br />

#include<br />

using namespace std;<br />

// Templates mit T als Parameter für den Datentyp (Platzhalter)<br />

template<br />

void tausche(T &a, T &b) {<br />

// a <strong>und</strong> b vertauschen<br />

const T temp = a;<br />

a = b;<br />

b = temp;<br />

}<br />

<strong>Breymann</strong> <strong>C++</strong>, c○ Hanser Verlag München<br />

Inhalt ◭◭ ◭ ◮ ◮◮ 136 zurück Ende

Hurra! Ihre Datei wurde hochgeladen und ist bereit für die Veröffentlichung.

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!