Sams Teach Yourself C++ in 21 Days
Listing 19.8 demonstrates the members of the vectorclass that have been discussed so far. You will see that the standard stringc ...
Templates 697 19 42: itsName = name; 43: } 44: 45: string Student::GetName() const 46: { 47: return itsName; 48: } 49: 50: void ...
91: cout << “GrowingClass(3):” << endl; 92: ShowVector(GrowingClass); 93: 94: GrowingClass[0] = Harry; 95: GrowingCl ...
Templates 699 19 GrowingClass(3) after assigning students: max_size() = 214748364 size() = 3 capacity() = 3 not empty New Studen ...
On line 90, a vector of three Studentobjects is defined. Its size and capacity are both three. Elements in the GrowingClassare a ...
Templates 701 19 The List Container A list is a container designed to be optimal when you are frequently inserting and delet- in ...
On line 4, you see the use of the typedefcommend. In this case, instead of using list<int>throughout the listing, the type ...
Templates 703 19 A stack is a LIFO(last in, first out) structure. The classic analogy for a stack is this: A stack is like a sta ...
Understanding Associative Containers .......................................................... You have seen that a vector is l ...
Templates 705 19 25: Student::Student() 26: : itsName(“New Student”), itsAge(16) 27: {} 28: 29: Student::Student(const string&am ...
74: void ShowMap(const map<T, A>& v); // display map properties 75: 76: typedef map<string, Student> SchoolClass ...
Templates 707 19 In this example, a class is created and four students are added. The list of stu- dents is then printed. After ...
Other Associative Containers Themultimapcontainer class is a mapclass without the restriction of unique keys. More than one elem ...
Templates 709 19 17: DoPrint(i); 18: return 0; 19: } 0 1 2 3 4 On lines 3–11, a template class named Printis defined. As you can ...
21: vInt[i] = i * 3; 22: 23: cout << “for_each()” << endl; 24: for_each(vInt.begin(), vInt.end(), DoPrint); 25: cout ...
Templates 711 19 19: 20: fill(vInt.begin(), vInt.begin() + 5, 1); 21: fill(vInt.begin() + 5, vInt.end(), 2); 22: 23: for_each(vI ...
The definition of the template determines the parameterized type. Each instance of the template is an actual object, which can b ...
Templates 713 19 Q When do I use general template friend classes? A When every instance, regardless of type, should be a friend ...
void append( int value ); int is_present( int value ) const; int is_empty() const { return head == 0; } int count() const { retu ...
DAY 20 WEEK 3 Handling Errors and Exceptions The code you’ve seen in this book has been created for illustration purposes. It ha ...
«
32
33
34
35
36
37
38
39
40
41
»
Free download pdf