|
| 1 | +#include <iostream> |
| 2 | +//#include <deque> |
| 3 | +#include <string> |
| 4 | + |
| 5 | +using namespace std; |
| 6 | + |
| 7 | +template<class T1, class T2, class T3> |
| 8 | +class Being { |
| 9 | +private: |
| 10 | + string name; |
| 11 | + T1 age; |
| 12 | + T2 height; |
| 13 | + T3 weight; |
| 14 | +public: |
| 15 | + Being(string newName, T1 newAge, T2 newHeight, T3 newWeight) |
| 16 | + : name(newName), age(newAge), height(newHeight), weight(newWeight) {} |
| 17 | + ~Being() {} |
| 18 | + string getName() const { return name; } |
| 19 | + T1 getAge() const { return age; } |
| 20 | + T2 getHeight() const { return height; } |
| 21 | + T3 getWeight() const { return weight; } |
| 22 | + virtual void hello() { |
| 23 | + cout << "Hello WOrld!\n"; |
| 24 | + } |
| 25 | +}; |
| 26 | + |
| 27 | +template<class T1, class T2, class T3> |
| 28 | +class Person : public Being<T1,T2,T3> { |
| 29 | +private: |
| 30 | + string city; |
| 31 | +public: |
| 32 | + Person(string nm, T1 ag, T2 hg, T3 wg, string newCity) |
| 33 | + : Being<T1, T2, T3>(nm, ag, hg, wg) |
| 34 | + { |
| 35 | + city = newCity; |
| 36 | + } |
| 37 | + ~Person() {} |
| 38 | + void hello() |
| 39 | + { |
| 40 | + cout << "\nName: " << Being<T1,T2,T3>::getName() << "\n" |
| 41 | + << "Age: " << Being<T1,T2,T3>::getAge() << "\n" |
| 42 | + << "Height: " << Being<T1,T2,T3>::getHeight() << "\n" |
| 43 | + << "Weight: " << Being<T1,T2,T3>::getWeight() << "\n" |
| 44 | + << "City: " << city << "\n\n"; |
| 45 | + } |
| 46 | +}; |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +int main() |
| 51 | +{ |
| 52 | + Person<int, double, double> diman("Dimos", 26, 1.78, 78.2, "Agrinio"); |
| 53 | + Person<int, double, double> * dim = &diman; |
| 54 | + //diman.hello(); |
| 55 | + //dim->hello(); |
| 56 | + |
| 57 | + const int SIZE = 3; |
| 58 | + Person<int, double, double> *arr[SIZE] = { |
| 59 | + new Person<int, double, double> ("Dimos", 26, 1.78, 78.2, "Agrinio"), |
| 60 | + new Person<int, double, double> ("George", 29, 1.70, 89.5, "Agrinio"), |
| 61 | + new Person<int, double, double> ("Andrew", 56, 1.74, 88.4, "Agrinio") |
| 62 | + }; |
| 63 | + |
| 64 | + for(unsigned i=0; i<SIZE; ++i) { |
| 65 | + arr[i]->hello(); |
| 66 | + } |
| 67 | + |
| 68 | + return 0; |
| 69 | +} |
0 commit comments