1 /* 2 * operator-overloading.cpp 3 * 4 * Beispiel-Programm Operator-Overloading 5 * 6 * Autor: H.Drachenfels 7 * Erstellt am: 7.8.2019 8 */
9 #include <iostream>
10
11 enum jahreszeit {fruehling, sommer, herbst, winter};
12
13 std::ostream& operator<<(std::ostream& os, jahreszeit j);
14
15 int main()
16 {
17 jahreszeit j = sommer;
18 std::cout << j << '\n';
19 operator<<(std::cout, j) << '\n';
20 }
21
22 std::ostream& operator<<(std::ostream& os, jahreszeit j)
23 {
24 static const char *jahreszeiten[] = {"Fruehling", "Sommer", "Herbst", "Winter"};
25 os << jahreszeiten[j];
26 return os;
27 }
28