Templates 697
19
42: itsName = name;
43: }
44:
45: string Student::GetName() const
46: {
47: return itsName;
48: }
49:
50: void Student::SetAge(const int age)
51: {
52: itsAge = age;
53: }
54:
55: int Student::GetAge() const
56: {
57: return itsAge;
58: }
59:
60: Student& Student::operator=(const Student& rhs)
61: {
62: itsName = rhs.GetName();
63: itsAge = rhs.GetAge();
64: return *this;
65: }
66:
67: ostream& operator<<(ostream& os, const Student& rhs)
68: {
69: os << rhs.GetName() << “ is “ << rhs.GetAge() << “ years old”;
70: return os;
71: }
72:
73: template<class T>
74: // display vector properties
75: void ShowVector(const vector<T>& v);
76:
77: typedef vector<Student> SchoolClass;
78:
79: int main()
80: {
81: Student Harry;
82: Student Sally(“Sally”, 15);
83: Student Bill(“Bill”, 17);
84: Student Peter(“Peter”, 16);
85:
86: SchoolClass EmptyClass;
87: cout << “EmptyClass:” << endl;
88: ShowVector(EmptyClass);
89:
90: SchoolClass GrowingClass(3);
LISTING19.8 continued