Next: Bsp. für Class-Template
Up: Templates, Exceptions sowie Pogrammierung
Previous: Templates
#include <iostream.h>
template <class T>
void swap(T& a, T& b)
{
const T t=a;
a = b;
b = t;
}
int main()
{
float a=65.2, b=75.4;
char c='a', d='c';
cout << "Vor Tausch: a,b="
<< a << ", " << b << " und c,d="
<< c << ", " << d << endl;
swap(a,b); swap(c,d);
cout << "Nach Tausch: a,b="
<< a << ", " << b << " und c,d="
<< c << ", " << d << endl;
}
| © 1997 Gottfried Rudorfer, C++-AG, Lehrveranstaltungen, Abteilung für Angewandte Informatik, Wirtschaftsuniversität Wien, 3/19/1998 |