Sams Teach Yourself C++ in 21 Days

(singke) #1
Templates 705

19


25: Student::Student()
26: : itsName(“New Student”), itsAge(16)
27: {}
28:
29: Student::Student(const string& name, const int age)
30: : itsName(name), itsAge(age)
31: {}
32:
33: Student::Student(const Student& rhs)
34: : itsName(rhs.GetName()), itsAge(rhs.GetAge())
35: {}
36:
37: Student::~Student()
38: {}
39:
40: void Student::SetName(const string& name)
41: {
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, class A>

LISTING19.10 continued

Free download pdf