1 /* 2 * gruss.h 3 * 4 * Variante des interface-Beispiels aus Teil 6 5 * mit parametrischer Polymorphie mittels template 6 * statt Subtyppolymorphie mittels Vererbung. 7 * 8 * Autor: H.Drachenfels 9 * Erstellt am: 2.6.2023 10 */
11
12 #ifndef GRUSS_H
13 #define GRUSS_H
14
15 #include <string>
16
17 template<typename T>
18 class gruss final
19 {
20 public:
21 gruss() = default;
22 T uhr;
23 std::string gruessen();
24 // entity: kein copy und move
25 gruss(const gruss&) = delete;
26 gruss& operator=(const gruss&) = delete;
27 gruss(gruss&&) = delete;
28 gruss& operator=(gruss&&) = delete;
29 };
30
31 template<typename T>
32 std::string gruss<T>::gruessen()
33 {
34 int stunde;
35 int minute;
36
37 this->uhr.ablesen(stunde, minute);
38
39 if (6 <= stunde && stunde < 11)
40 {
41 return "Guten Morgen";
42 }
43
44 if (11 <= stunde && stunde < 18)
45 {
46 return "Guten Tag";
47 }
48
49 if (18 <= stunde && stunde <= 23)
50 {
51 return "Guten Abend";
52 }
53
54 throw std::string("Nachtruhe!");
55 }
56
57 #endif
58