Preface |
|
xxix | |
Dedication |
|
xxxi | |
List Of Figures |
|
xxxiii | |
List Of Programs |
|
xxxv | |
Introduction |
|
1 | (6) |
Part I Imperative Programming (1) |
|
7 | (72) |
|
|
8 | (9) |
|
1.1 Setting Up the Programming Environment |
|
|
8 | (1) |
|
|
9 | (1) |
|
|
9 | (3) |
|
1.3 Writing C++ Source Code |
|
|
12 | (2) |
|
|
12 | (1) |
|
1.3.1.1 Style with Primitive Tools |
|
|
13 | (1) |
|
|
13 | (1) |
|
1.4 Subsequent Stages in Building a Program |
|
|
14 | (1) |
|
|
14 | (1) |
|
|
14 | (1) |
|
|
15 | (1) |
|
|
15 | (1) |
|
|
15 | (2) |
|
1.5.1 What are Bugs/Errors? |
|
|
15 | (1) |
|
1.5.2 Compile-Time Errors |
|
|
16 | (1) |
|
|
16 | (1) |
|
|
16 | (1) |
|
|
17 | (1) |
|
|
17 | (20) |
|
|
17 | (3) |
|
2.1.1 Performing Calculations |
|
|
17 | (1) |
|
2.1.2 Interacting with the Console Window |
|
|
18 | (2) |
|
|
20 | (3) |
|
|
20 | (1) |
|
|
20 | (1) |
|
|
21 | (1) |
|
2.2.2 Initialising a Variable |
|
|
21 | (1) |
|
2.2.2.1 Using Assignment Equals = |
|
|
22 | (1) |
|
2.2.2.2 Using Parentheses () |
|
|
22 | (1) |
|
2.2.2.3 Which is Preferable? |
|
|
22 | (1) |
|
2.2.3 Ensuring Read Only Status Using Const |
|
|
22 | (1) |
|
|
23 | (4) |
|
|
24 | (3) |
|
2.3.1.1 Prospective Problems with certain types |
|
|
25 | (1) |
|
2.3.1.2 Static Casting of Types |
|
|
25 | (1) |
|
2.3.1.3 Solution with Type Casting |
|
|
25 | (2) |
|
|
27 | (1) |
|
|
27 | (10) |
|
2.4.1 Mathematical Operators |
|
|
27 | (8) |
|
2.4.1.1 Arithmetic Operators |
|
|
27 | (1) |
|
2.4.1.2 Assignment & Equality Operators |
|
|
27 | (1) |
|
2.4.1.2.1 Assignment Operations using = |
|
|
28 | (1) |
|
2.4.1.2.2 = Operator in Mathematics and Computer Science |
|
|
28 | (1) |
|
2.4.1.2.3 Equality Operations using == |
|
|
29 | (1) |
|
2.4.1.2.4 Compound Assignment Operators |
|
|
29 | (1) |
|
2.4.1.2.5 Assignment vs Compound Assignment Operators |
|
|
30 | (1) |
|
2.4.1.3 Increment & Decrement Operators |
|
|
30 | (1) |
|
|
31 | (1) |
|
|
31 | (1) |
|
2.4.1.3.3 Similarities & Differences: Pre Increment & Post Increment |
|
|
31 | (3) |
|
2.4.1.4 Bitwise Operators |
|
|
34 | (1) |
|
|
35 | (1) |
|
2.4.3 The Sizeof Operator |
|
|
35 | (2) |
|
|
37 | (34) |
|
3.1 Conditional Statements |
|
|
37 | (13) |
|
|
37 | (2) |
|
3.1.1.1 What is a condition? |
|
|
38 | (1) |
|
3.1.2 The if, Then, Else Clause |
|
|
39 | (4) |
|
3.1.2.1 Alternative Form using the Ternary? : Operator |
|
|
41 | (2) |
|
3.1.3 Cascaded/Nested if Statements |
|
|
43 | (2) |
|
3.1.4 The if, Else if, Else Clause |
|
|
45 | (2) |
|
|
47 | (3) |
|
3.1.6 Switch Statement vs if, Else if, Else Clause |
|
|
50 | (1) |
|
3.2 Problem Solving with Loops |
|
|
50 | (11) |
|
|
50 | (1) |
|
|
51 | (3) |
|
|
54 | (2) |
|
|
56 | (1) |
|
|
56 | (5) |
|
3.3 C++ Statements & Constructs |
|
|
61 | (8) |
|
|
61 | (1) |
|
|
61 | (1) |
|
|
62 | (2) |
|
|
64 | (2) |
|
3.3.4.1 Prospective Evils of the goto statement |
|
|
66 | (1) |
|
3.3.5 Dropping the Braces 0 For 1 Action |
|
|
66 | (3) |
|
3.3.5.1 Potential Hazards in dropping the Braces |
|
|
67 | (1) |
|
3.3.5.1.1 Breaking at the Wrong Place |
|
|
67 | (1) |
|
3.3.5.1.2 Dangling Else Clause Issue |
|
|
68 | (1) |
|
3.3.5.2 Guideline with Braces |
|
|
69 | (1) |
|
3.4 Creating Aliases IN C & C++ |
|
|
69 | (2) |
|
3.4.1 Defining Constants Using #Define - Avoid in C++ |
|
|
69 | (1) |
|
3.4.1.1 Issues with Macro Aliases |
|
|
70 | (1) |
|
|
70 | (4) |
|
3.4.2.1 Cannot modify Typedef |
|
|
70 | (1) |
|
|
71 | (8) |
|
4.1 Good vs Bad Practices |
|
|
71 | (3) |
|
|
74 | (1) |
|
|
74 | (1) |
|
4.2.2 Naming of Variables |
|
|
74 | (1) |
|
4.2.3 Formatting of Source Code |
|
|
75 | (1) |
|
|
75 | (5) |
|
|
75 | (1) |
|
|
76 | (1) |
|
|
77 | (2) |
Part II Procedural Programming |
|
79 | (88) |
|
|
80 | (33) |
|
|
80 | (1) |
|
5.1.1 Procedural Thinking Outside the Programming World |
|
|
80 | (1) |
|
5.1.2 Procedural Thinking Inside the Programming World |
|
|
81 | (1) |
|
|
81 | (5) |
|
|
82 | (1) |
|
5.2.2 Function Definitions |
|
|
83 | (1) |
|
5.2.3 Function Declarations |
|
|
84 | (1) |
|
5.2.3.1 Signature of a Function (1) |
|
|
84 | (1) |
|
5.2.4 Function Invocation |
|
|
85 | (1) |
|
5.2.4.1 Caution: Circular Reference |
|
|
85 | (1) |
|
5.2.5 Declarations vs Definitions |
|
|
86 | (1) |
|
5.3 Functions: No Inputs, No Output |
|
|
86 | (3) |
|
5.4 Functions: Some Inputs, No Output |
|
|
89 | (9) |
|
5.4.1 Signature of a Function (2) |
|
|
92 | (1) |
|
5.4.2 Formal Parameters vs. Actual Parameters |
|
|
93 | (1) |
|
5.4.3 Passing a Copy of the Value |
|
|
93 | (1) |
|
5.4.4 No Predetermined Order of Evaluation of Actual Parameters |
|
|
93 | (1) |
|
5.4.5 Modifying Formal Parameters |
|
|
94 | (4) |
|
|
94 | (3) |
|
5.4.5.2 Const Formal Parameters |
|
|
97 | (1) |
|
5.5 Functions: Some Inputs, an output |
|
|
98 | (3) |
|
|
101 | (1) |
|
|
101 | (1) |
|
|
102 | (6) |
|
|
104 | (1) |
|
5.7.1.1 Prospective Evils of Global Variables |
|
|
104 | (1) |
|
|
105 | (3) |
|
5.7.2.1 Automatic Local Variables |
|
|
105 | (1) |
|
5.7.2.2 Static Local Variables |
|
|
106 | (1) |
|
5.7.2.2.1 Initialising Static Local Variables |
|
|
108 | (1) |
|
5.7.2.2.2 Caution with Static Local Variables |
|
|
108 | (1) |
|
5.8 Debugging: Single Step In |
|
|
108 | (2) |
|
5.8.1 The Debug/Call Stack |
|
|
110 | (1) |
|
5.9 Overloading Functions |
|
|
110 | (3) |
|
5.9.1 Prospective Evils of Function Overloading |
|
|
113 | (1) |
|
6 Inline Functions and Macros |
|
|
113 | (10) |
|
6.1 Function Invocation Overhead |
|
|
113 | (1) |
|
6.2 C Macros - For the Best Part Avoid in C++ |
|
|
114 | (6) |
|
|
114 | (2) |
|
6.2.2 Conditional Preprocessor Directives |
|
|
116 | (2) |
|
6.2.2.1 The #ifdef, #ifndef #endif Clause |
|
|
116 | (2) |
|
6.2.3 Prospective Evils of Macros |
|
|
118 | (2) |
|
6.2.3.1 Losing Track of Types |
|
|
118 | (1) |
|
6.2.3.2 Losing Track of the Name |
|
|
119 | (1) |
|
6.2.3.3 Operator Precedence Problems |
|
|
119 | (1) |
|
6.2.4 Rules of Thumb with Macros |
|
|
120 | (1) |
|
|
120 | (3) |
|
6.3.1 Defining & Declaring Inline Functions |
|
|
120 | (1) |
|
6.3.2 Using Inline Functions |
|
|
121 | (1) |
|
6.3.3 The Inline Keyword: A Request, Not an Instruction |
|
|
122 | (1) |
|
6.3.4 Macro Problems not Manifest in Inline Functions |
|
|
122 | (1) |
|
7 Program Management Over Multiple Files |
|
|
123 | (19) |
|
|
123 | (4) |
|
|
124 | (3) |
|
7.2 Building C++ Projects |
|
|
127 | (1) |
|
|
127 | (1) |
|
|
128 | (1) |
|
7.3 Controlling Visibility |
|
|
128 | (4) |
|
7.3.1 Creating External Visibility Using Extern |
|
|
128 | (2) |
|
7.3.1.1 Linker Error caused by a Lack of Definition |
|
|
129 | (1) |
|
7.3.2 Hiding External Visibility Using Static |
|
|
130 | (5) |
|
7.3.2.1 Duplication of the keyword static |
|
|
132 | (1) |
|
|
132 | (2) |
|
7.5 Potential Problem: Multiple Inclusions |
|
|
134 | (1) |
|
7.6 Preventing Multiple Inclusions |
|
|
135 | (7) |
|
7.6.1 Ensuring Single Inclusions Using Macros |
|
|
135 | (4) |
|
7.6.1.1 Using #ifndef to prevent Multiple Inclusions |
|
|
135 | (4) |
|
7.6.2 Ensuring Single Inclusions Using Preprocessor Directives |
|
|
139 | (3) |
|
|
142 | (25) |
|
|
142 | (4) |
|
8.1.1 Recursion Outside the Programming World |
|
|
142 | (4) |
|
8.1.2 Recursion Inside the Programming World |
|
|
146 | (1) |
|
8.2 Caution with Recursion |
|
|
146 | (1) |
|
|
147 | (4) |
|
8.3.1 Iterative Algorthm: Using Loops |
|
|
147 | (2) |
|
|
149 | (2) |
|
|
151 | (3) |
|
8.4.1 Applications of the Fibonacci Sequence |
|
|
154 | (1) |
|
8.5 Generating Permutations |
|
|
154 | (3) |
|
|
155 | (1) |
|
8.5.2 The Next Permutation Algorithm |
|
|
155 | (2) |
|
|
157 | (7) |
|
8.6.1 Strategy for 3 Rings |
|
|
158 | (1) |
|
8.6.2 Strategy for 4 Rings |
|
|
158 | (1) |
|
8.6.3 Iterative Strategies |
|
|
159 | (1) |
|
8.6.4 Recursive Strategies |
|
|
159 | (1) |
|
8.6.5 Implementing Recursion in Hanoi Towers |
|
|
160 | (3) |
|
8.6.6 Traditional Legends of Hanoi Towers |
|
|
163 | (1) |
|
8.7 Further Recursive Problems |
|
|
164 | (3) |
|
|
164 | (1) |
|
8.7.2 Knapsack/Rucksack Problem |
|
|
165 | (1) |
|
|
165 | (2) |
Part III Data Structures & Algorithms |
|
167 | (12) |
|
|
167 | (12) |
|
|
167 | (2) |
|
9.1.1 Homogeneous Nature of Data Structures |
|
|
168 | (1) |
|
|
168 | (1) |
|
|
169 | (1) |
|
9.1.4 Storage in Runtime Memory |
|
|
169 | (1) |
|
|
169 | (1) |
|
9.3 Writing Data to an Array |
|
|
170 | (1) |
|
9.4 Defining and Initialising Arrays |
|
|
170 | (1) |
|
9.4.1 Defining and Initialising Separately |
|
|
170 | (1) |
|
9.4.1.1 Stand Alone Definition |
|
|
170 | (1) |
|
|
170 | (1) |
|
9.4.2 Defining and Initialising on the same Line |
|
|
171 | (1) |
|
9.5 Reading Data from an Array |
|
|
171 | (1) |
|
|
171 | (2) |
|
9.7 Arrays as Function Inputs |
|
|
173 | (2) |
|
|
175 | (1) |
|
9.9 Multidimensional Arrays |
|
|
175 | (2) |
|
|
177 | (2) |
Part IV Memory & Resource Management Programming |
|
179 | (80) |
|
|
181 | (19) |
|
10.1 What is the Practice of Addressing? |
|
|
181 | (1) |
|
10.1.1 Addressing Outside the Programming World |
|
|
181 | (1) |
|
10.1.2 Addressing Inside the Programming World |
|
|
182 | (1) |
|
|
182 | (2) |
|
10.2.1 L-Value vs R-Value |
|
|
183 | (1) |
|
10.2.2 The Importance of Pointers |
|
|
183 | (1) |
|
10.3 Implementing Pointers in C & C++ |
|
|
184 | (8) |
|
10.3.1 Defining Pointers: The * Operator |
|
|
184 | (2) |
|
10.3.1.1 Placing the Asterisk BEFORE the Space |
|
|
185 | (1) |
|
10.3.1.2 Placing the Asterisk AFTER the Space |
|
|
185 | (1) |
|
10.3.2 Populating Pointers: The & Operator |
|
|
186 | (1) |
|
10.3.2.1 Definition and Population in the same line |
|
|
187 | (1) |
|
10.3.3 Decoding Pointers: The * Operator |
|
|
187 | (1) |
|
10.3.4 Demonstration: Creating & Using Pointers |
|
|
187 | (2) |
|
10.3.5 Potential Problem: Type Mismatch |
|
|
189 | (1) |
|
|
189 | (2) |
|
10.3.7 Review: 2 Uses of the Asterisk Operator |
|
|
191 | (1) |
|
|
192 | (1) |
|
10.4.1 What is the NULL Pointer? |
|
|
192 | (1) |
|
10.4.1.1 Do not Confuse NULL Pointers and NUL Characters |
|
|
192 | (1) |
|
10.4.2 Defining the NULL Pointer |
|
|
192 | (1) |
|
10.4.3 Applications of the NULL Pointer |
|
|
193 | (1) |
|
|
193 | (2) |
|
10.5.1 Issues with the Void Pointer |
|
|
194 | (1) |
|
10.6 Pointers as Function Inputs |
|
|
195 | (4) |
|
10.6.1 Problems: Lack of Addressing |
|
|
195 | (1) |
|
10.6.2 Passing Function Inputs as Pointers |
|
|
196 | (1) |
|
10.6.2.1 Formal Parameters as Pointers |
|
|
196 | (1) |
|
10.6.2.2 Actual Parameters as Pointers |
|
|
197 | (1) |
|
10.6.3 Fixing the Problems Using Pointer Inputs |
|
|
197 | (2) |
|
10.6.4 The Importance of Pointer Inputs |
|
|
199 | (1) |
|
10.7 The Pointer as the Function Output |
|
|
199 | (1) |
|
10.7.1 Prospective Dangling Pointer Problem |
|
|
200 | (1) |
|
|
200 | (9) |
|
11.1 Pointer to Pointer Hierarchies |
|
|
200 | (4) |
|
11.1.1 One Level: Pointer to a Pointer |
|
|
200 | (2) |
|
11.1.2 Multiple Level Pointers |
|
|
202 | (2) |
|
11.2 Read-Only Pointers Using Const |
|
|
204 | (2) |
|
11.3 Pointers to Functions |
|
|
206 | (1) |
|
|
206 | (3) |
|
11.4.1 Array of Pointers to Primitive Variables |
|
|
207 | (1) |
|
11.4.2 Array of Pointers to Functions |
|
|
208 | (1) |
|
|
209 | (8) |
|
12.1 What are References? |
|
|
209 | (1) |
|
12.1.1 L-Value vs R-Value |
|
|
209 | (1) |
|
12.1.2 Restrictions with References |
|
|
209 | (1) |
|
12.2 Implementing References in C++ |
|
|
210 | (2) |
|
12.2.1 Defining References |
|
|
210 | (1) |
|
12.2.2 Populating References |
|
|
210 | (1) |
|
12.2.3 Decoding References |
|
|
211 | (1) |
|
|
212 | (1) |
|
12.4 References as Function Inputs |
|
|
213 | (4) |
|
12.4.1 Problems: Lack of Addressing |
|
|
213 | (1) |
|
12.4.2 Passing Function Inputs as References |
|
|
214 | (1) |
|
12.4.2.1 Formal Parameters as References |
|
|
214 | (1) |
|
12.4.2.2 Actual Parameters as References |
|
|
215 | (1) |
|
12.4.3 Fixing the Problems Using References |
|
|
215 | (2) |
|
|
217 | (2) |
|
13.1 Read-Only References Using Const |
|
|
217 | (2) |
|
13.2 Potential Ambiguities in Reference Notation |
|
|
219 | (1) |
|
13.3 Reference to a Function |
|
|
219 | (1) |
|
14 Runtime Memory Management |
|
|
219 | (17) |
|
|
219 | (1) |
|
|
220 | (3) |
|
14.2.1 LIFO: Last in First Out Nature |
|
|
220 | (3) |
|
|
223 | (1) |
|
14.3 The Runtime Heap/Free Store |
|
|
223 | (2) |
|
|
223 | (1) |
|
14.3.2 The Delete Operator |
|
|
224 | (1) |
|
14.3.2.1 Dangling Pointer |
|
|
224 | (1) |
|
14.4 Using the Runtime Heap |
|
|
225 | (3) |
|
14.4.1 Direct Usage from the Stack |
|
|
225 | (1) |
|
14.4.2 Sharing the Runtime Heap Between Function Calls |
|
|
226 | (2) |
|
14.5 Prospective Bugs When Using the Runtime Heap |
|
|
228 | (4) |
|
|
228 | (2) |
|
|
230 | (1) |
|
|
231 | (1) |
|
|
232 | (1) |
|
14.6 Malloc() and free() From C Programming |
|
|
232 | (1) |
|
14.7 Using Both the Runtime Stack and Heap |
|
|
232 | (3) |
|
14.7.1 When to Use Which Runtime Memory |
|
|
235 | (1) |
|
|
235 | (1) |
|
14.8.1 The New[ ] and Delete[ ] Operators |
|
|
236 | (1) |
|
15 Pointers vs References |
|
|
236 | (6) |
|
15.1 Contrast: Definitions and Usage |
|
|
237 | (4) |
|
15.2 Rules of Thumb: When to Use Pointers & References |
|
|
241 | (1) |
|
16 Pointers vs Arrays: Mostly Interchangeable, Sometimes Not |
|
|
242 | (17) |
|
16.1 The Nature of Pointers & Arrays |
|
|
242 | (2) |
|
16.1.1 Placement in Runtime Memory |
|
|
242 | (1) |
|
16.1.2 Array and Pointer Operators |
|
|
243 | (1) |
|
16.2 Where Arrays and Pointers are Interchangeable |
|
|
244 | (4) |
|
16.2.1 Mixing Pointer and Array Syntaxes in Definitions and Accessing |
|
|
244 | (3) |
|
16.2.1.1 Define as Pointer, accessed as Array |
|
|
246 | (1) |
|
16.2.1.2 Array of Pointers |
|
|
247 | (1) |
|
16.2.2 Input to a Function |
|
|
247 | (1) |
|
16.3 Where Arrays and Pointers are Not Interchangeable |
|
|
248 | (8) |
|
16.3.1 Definition as Array, Declaration as a Pointer from a Separate File |
|
|
248 | (2) |
|
16.3.2 Output of a Function |
|
|
250 | (2) |
|
16.3.3 Using the Assignment Operator |
|
|
252 | (1) |
|
16.3.4 Using the Sizeof Operator |
|
|
253 | (1) |
|
16.3.5 Using the Contents of "*" Operator |
|
|
254 | (2) |
|
16.4 Arrays & References: Not Interchangeable |
|
|
256 | (1) |
|
16.5 Summary: Interchangeability of Arrays and Pointers |
|
|
256 | (3) |
Part V Object Oriented Programming |
|
259 | (254) |
|
|
260 | (20) |
|
17.1 What is Abstraction? |
|
|
260 | (5) |
|
17.1.1 Abstraction Outside the Programming World |
|
|
260 | (3) |
|
17.1.2 Problems: Lack of Abstraction |
|
|
263 | (2) |
|
17.1.3 Introducing Abstraction |
|
|
265 | (1) |
|
17.2 What are Abstract Data Types? |
|
|
265 | (1) |
|
|
266 | (4) |
|
17.3.1 Defining Structures |
|
|
266 | (1) |
|
17.3.2 Instantiating Structures |
|
|
267 | (1) |
|
17.3.3 Accessing Member Data Using the DOT Operators |
|
|
267 | (1) |
|
|
267 | (2) |
|
17.3.5 Possible Notation Using Typedef |
|
|
269 | (1) |
|
17.3.6 Limitations of Structures |
|
|
269 | (1) |
|
|
270 | (2) |
|
|
272 | (3) |
|
|
272 | (1) |
|
|
272 | (3) |
|
17.5.2.1 Popularity of Enum Use |
|
|
274 | (1) |
|
|
275 | (2) |
|
17.6.1 Definition and Population |
|
|
275 | (1) |
|
17.6.2 The "Arrow" Operator |
|
|
275 | (2) |
|
17.6.2.1 Preference Over the Dot Operator |
|
|
277 | (1) |
|
|
277 | (3) |
|
17.7.1 Definition and Population |
|
|
278 | (1) |
|
17.7.2 Access Using the Dot Operator |
|
|
278 | (2) |
|
|
280 | (56) |
|
18.1 What is Encapsulation? |
|
|
280 | (2) |
|
18.1.1 Encapsulation Outside the Programming World |
|
|
280 | (2) |
|
18.2 Implementing Abstraction & Encapsulation in C++ |
|
|
282 | (1) |
|
18.2.1 Terminology - Native Class |
|
|
283 | (1) |
|
|
283 | (1) |
|
18.3 Structure of a Class |
|
|
283 | (1) |
|
18.3.1 Knowledge & Skill Analogy |
|
|
284 | (1) |
|
18.4 Implementing a C++ Class - Method 1 of 2 |
|
|
284 | (2) |
|
18.4.1 Scope of a Variable (2) |
|
|
285 | (1) |
|
18.5 Implementing Objects |
|
|
286 | (13) |
|
18.5.1 Objects on the Runtime Stack |
|
|
286 | (2) |
|
18.5.1.1 Creating Objects Directly |
|
|
286 | (1) |
|
18.5.1.1.1 The Dot Operator |
|
|
286 | (1) |
|
18.5.1.1.2 Equating Objects |
|
|
287 | (1) |
|
|
288 | (2) |
|
18.5.3 Pointers to Objects |
|
|
290 | (2) |
|
18.5.3.1 Definition and Population |
|
|
290 | (1) |
|
18.5.3.2 The "Arrow" Operator |
|
|
290 | (1) |
|
18.5.3.2.1 Preference over the dot operator |
|
|
290 | (1) |
|
18.5.3.3 Using Pointers to Objects |
|
|
291 | (1) |
|
18.5.4 References to Objects |
|
|
292 | (2) |
|
18.5.4.1 Definition and Population |
|
|
292 | (1) |
|
18.5.4.2 Access Using the Dot Operator |
|
|
292 | (1) |
|
18.5.4.3 Using References to Objects |
|
|
293 | (1) |
|
18.5.5 Objects on the Runtime Heap |
|
|
294 | (2) |
|
18.5.5.1 Definition and Population |
|
|
294 | (1) |
|
18.5.5.2 Using Objects on the Runtime Heap |
|
|
294 | (1) |
|
18.5.5.3 Java & C# - All Objects on the Heap |
|
|
295 | (1) |
|
18.5.6 Objects as Function Inputs |
|
|
296 | (2) |
|
18.5.7 Object as the Function Output |
|
|
298 | (1) |
|
18.6 Implementing a C++ Class - Method 2 of 2 |
|
|
299 | (6) |
|
18.6.1 The Scope Resolution Operator |
|
|
300 | (1) |
|
18.6.2 Separating the Declaration & Definitions Lexically |
|
|
300 | (2) |
|
18.6.3 Managing a Class Over Multiple Files |
|
|
302 | (3) |
|
18.7 Defining a Class: Definition & Declarations, Together vs Separate |
|
|
305 | (1) |
|
18.8 Special Class Members |
|
|
305 | (1) |
|
|
306 | (17) |
|
18.9.1 What are Constructors? |
|
|
306 | (1) |
|
18.9.2 Rules of Constructors |
|
|
307 | (1) |
|
18.9.3 Using Constructors |
|
|
308 | (3) |
|
18.9.3.1 Defining Constructors |
|
|
308 | (1) |
|
18.9.3.2 Invoking Constructors |
|
|
308 | (3) |
|
18.9.4 Overloading Constructors |
|
|
311 | (4) |
|
18.9.4.1 Defining Overloaded Constructors |
|
|
311 | (1) |
|
18.9.4.2 Invoking Overloaded Constructors |
|
|
312 | (3) |
|
18.9.5 Default Constructor |
|
|
315 | (1) |
|
18.9.6 Alternative Means of Initialising Data Members |
|
|
315 | (1) |
|
18.9.7 Further Initialisation Work in Constructors |
|
|
316 | (7) |
|
|
323 | (7) |
|
18.10.1 What are Destructors? |
|
|
323 | (1) |
|
18.10.2 Rules of Destructors |
|
|
324 | (1) |
|
18.10.3 Using Destructors |
|
|
324 | (5) |
|
18.10.4 Default Destructor |
|
|
329 | (1) |
|
18.11 Constructors and Destructors for Objects on the Runtime Heap |
|
|
330 | (6) |
|
19 Object Oriented Design Using UML |
|
|
336 | (3) |
|
|
336 | (1) |
|
|
336 | (2) |
|
|
336 | (1) |
|
|
337 | (1) |
|
|
338 | (1) |
|
19.3 Beauties of Object Oriented Programming |
|
|
338 | (1) |
|
20 Abstraction & Encapsulation Using Classes & Objects (2) |
|
|
339 | (79) |
|
20.1 Mutator Member Function |
|
|
340 | (7) |
|
20.1.1 What are Mutators? |
|
|
340 | (1) |
|
20.1.1.1 Mutators do not violate Encapsulation |
|
|
341 | (1) |
|
20.1.2 Defining and Using Mutators |
|
|
341 | (6) |
|
20.2 Const Member Functions |
|
|
347 | (7) |
|
20.2.1 What is a Const Member Function? |
|
|
347 | (1) |
|
20.2.2 Making a Member Function Const |
|
|
348 | (1) |
|
20.2.3 Using Const Member Function |
|
|
348 | (6) |
|
|
354 | (8) |
|
20.3.1 What are Static Data Members? |
|
|
354 | (1) |
|
20.3.2 Initialising Static Data Members |
|
|
354 | (1) |
|
20.3.3 Using Static Data Members |
|
|
354 | (8) |
|
20.4 Static Member Functions |
|
|
362 | (8) |
|
20.4.1 What are Static Member Functions? |
|
|
362 | (1) |
|
20.4.1.1 Rules of Static Member Functions? |
|
|
362 | (1) |
|
20.4.2 Using the Static Member Functions |
|
|
363 | (7) |
|
|
370 | (2) |
|
20.5.1 What is the Assignment Operator? |
|
|
370 | (1) |
|
20.5.2 Using the Assignment Operator |
|
|
371 | (1) |
|
20.5.3 Default Assignment Operator |
|
|
371 | (1) |
|
|
372 | (9) |
|
20.6.1 What is the Copy Constructor? |
|
|
372 | (2) |
|
20.6.1.1 Assignment vs. Initialisation |
|
|
372 | (1) |
|
20.6.1.2 Essential Nature of the Copy Constructor |
|
|
373 | (1) |
|
20.6.1.3 Rules of the Copy Constructor |
|
|
373 | (1) |
|
20.6.1.3.1 Input of a Copy Constructor |
|
|
374 | (1) |
|
20.6.1.4 Constructor vs. Copy Constructor |
|
|
374 | (1) |
|
20.6.2 Implementing and Using the Copy Constructor |
|
|
374 | (7) |
|
20.6.3 Default Copy Constructor |
|
|
381 | (1) |
|
|
381 | (8) |
|
20.7.1 What is the this Pointer? |
|
|
381 | (1) |
|
20.7.2 Using the this Pointer |
|
|
382 | (7) |
|
|
389 | (1) |
|
|
390 | (11) |
|
|
390 | (10) |
|
20.9.1.1 What are Nested Classes |
|
|
390 | (1) |
|
20.9.1.2 Rules of Nested Classes |
|
|
390 | (1) |
|
20.9.1.3 Creating and Using Nested Classes |
|
|
391 | (9) |
|
|
400 | (1) |
|
20.10 Explicit Constructors |
|
|
401 | (7) |
|
20.10.1 Implicit Conversions |
|
|
401 | (7) |
|
20.10.2 Preventing Implicit Conversions Using Explicit Constructors |
|
|
408 | (1) |
|
20.11 What a Class Creates Behind the Scenes |
|
|
408 | (1) |
|
|
409 | (9) |
|
|
409 | (3) |
|
|
412 | (5) |
|
20.12.3 Properties of Friendship |
|
|
417 | (1) |
|
20.12.4 Prospective Evils of Friendship |
|
|
417 | (1) |
|
20.12.5 Refined Definitions of Access Specifiers |
|
|
417 | (1) |
|
|
418 | (24) |
|
21.1 What is Operator Overloading? |
|
|
418 | (3) |
|
21.1.1 C++ Operators - Most but not all can be Overloaded |
|
|
418 | (2) |
|
21.1.1.1 Prohibited Overloads |
|
|
419 | (1) |
|
21.1.2 Implementing Operator Overloading |
|
|
420 | (1) |
|
21.2 Overloading Unary Operators |
|
|
421 | (6) |
|
21.2.1 Overloading the Increment Operators |
|
|
421 | (6) |
|
21.3 Overloading Binary Operators |
|
|
427 | (8) |
|
21.4 Overloading the Assignment Operator |
|
|
435 | (5) |
|
21.4.1 Arguments for & Against Overloading = |
|
|
439 | (1) |
|
21.5 Advanced Uses of Operator Overloading |
|
|
440 | (1) |
|
21.6 Prospective Evils of Operator Overloading |
|
|
440 | (2) |
|
|
442 | (40) |
|
22.1 What is Inheritance? |
|
|
442 | (1) |
|
|
442 | (1) |
|
22.2 Modelling Inheritance in UML |
|
|
442 | (4) |
|
22.2.1 Inheritance Outside the Programming World |
|
|
443 | (1) |
|
22.2.2 Inheritance Inside the Computer World |
|
|
444 | (2) |
|
22.3 C++ Syntax: Inheritance |
|
|
446 | (1) |
|
22.3.1 Single Inheritance |
|
|
446 | (1) |
|
22.3.2 Multiple Inheritance |
|
|
446 | (1) |
|
22.4 The Access Specifier "Protected" |
|
|
447 | (1) |
|
22.4.1 Prospective Evils of Protected |
|
|
447 | (1) |
|
22.5 Categories of Inheritance |
|
|
448 | (2) |
|
22.5.1 Single, Multiple Inheritance |
|
|
448 | (1) |
|
22.5.2 Implementation, Interface |
|
|
449 | (1) |
|
|
449 | (1) |
|
22.5.3 Public, Protected, Private Inheritance |
|
|
449 | (1) |
|
22.6 Constructor & Destructor Calls in Inherited Classes |
|
|
450 | (1) |
|
22.7 Single Implementation Inheritance |
|
|
451 | (8) |
|
22.8 Single Interface Inheritance |
|
|
459 | (3) |
|
|
459 | (1) |
|
22.8.2 Using Interface Inheritance |
|
|
459 | (2) |
|
22.8.3 Beauties of Interface Inheritance |
|
|
461 | (1) |
|
22.9 Multiple Implementation Inheritance |
|
|
462 | (10) |
|
22.9.1 Reasons for Multiple Implementation Inheritance |
|
|
462 | (1) |
|
22.9.2 Creating Multiple Implementation Inheritance |
|
|
462 | (4) |
|
22.9.3 Prospective Evils of Multiple Implementation Inheritance |
|
|
466 | (16) |
|
|
466 | (1) |
|
22.9.3.1.1 Resolving Using the Scope Resolution Operator |
|
|
466 | (1) |
|
22.9.3.2 Diamond Shaped Multiple Inheritance |
|
|
467 | (1) |
|
22.9.3.2.1 Resolving Using Virtual Inheritance/Virtual Classes |
|
|
468 | (3) |
|
22.9.3.3 Potential Lack of Organisation |
|
|
471 | (1) |
|
22.9.3.4 Multiple Inheritance in other OOP Languages |
|
|
472 | (1) |
|
22.10 Multiple Interface Inheritance |
|
|
472 | (3) |
|
22.11 Private & Protected Inheritance |
|
|
475 | (6) |
|
22.12 Full Definitions of Access Specifiers |
|
|
481 | (1) |
|
22.13 Suggested Rules of Thumb |
|
|
482 | (1) |
|
|
482 | (31) |
|
23.1 What is Polymorphism? |
|
|
482 | (1) |
|
23.1.1 Polymorphism Outside the Programming World |
|
|
482 | (1) |
|
23.2 Implementing Polymorphism in C++ |
|
|
483 | (11) |
|
|
483 | (1) |
|
23.2.2 OOP Inheritance Hierarchy |
|
|
484 | (1) |
|
23.2.3 Virtual Member Functions |
|
|
485 | (1) |
|
23.2.4 Pointers in Inheritance Hierarchies |
|
|
486 | (1) |
|
23.2.5 Polymorphism on the Runtime Stack |
|
|
487 | (4) |
|
|
491 | (1) |
|
23.2.7 Polymorphism on the Runtime Heap |
|
|
492 | (2) |
|
23.3 Pure Virtual Member Functions |
|
|
494 | (8) |
|
23.3.1 Interface Inheritance |
|
|
494 | (1) |
|
|
495 | (1) |
|
23.3.3 Class Forced to be Abstract |
|
|
496 | (1) |
|
23.3.4 Using Pure Virtual Functions |
|
|
496 | (6) |
|
23.4 Beauties of Polymorphism |
|
|
502 | (2) |
|
23.4.1 The Essential Nature of Polymorphism |
|
|
502 | (1) |
|
23.4.2 Pointers Preferred Over References |
|
|
503 | (1) |
|
23.5 Data Structures of Polymorphic Objects |
|
|
504 | (6) |
|
|
510 | (1) |
|
23.7 Further Polymorphism |
|
|
511 | (2) |
Part VI Imperative Programming (2) |
|
513 | (46) |
|
|
513 | (12) |
|
24.1 What is Exception Handling? |
|
|
513 | (1) |
|
24.1.1 When to Use Exception Handling |
|
|
514 | (1) |
|
24.1.2 Exception Handling in C++ |
|
|
514 | (1) |
|
24.2 Anatomy of an Exception Handler |
|
|
514 | (1) |
|
24.3 Exception: Division by Zero |
|
|
515 | (3) |
|
24.4 Exception: User Input of Inappropriate Type |
|
|
518 | (3) |
|
24.5 Exception: Out of Bounds Array |
|
|
521 | (3) |
|
|
524 | (1) |
|
24.7 Warning: Never Get A Destructor to Throw an Exception |
|
|
524 | (1) |
|
24.8 Catching Multiple Exceptions |
|
|
524 | (1) |
|
|
525 | (34) |
|
25.1 The C++ I/O Stream Classes |
|
|
525 | (1) |
|
25.2 Giving Inputs to the Main Function |
|
|
526 | (2) |
|
25.3 Working with Text Files |
|
|
528 | (10) |
|
25.3.1 Reading From a Text File |
|
|
528 | (3) |
|
25.3.2 Writing to a Text File |
|
|
531 | (5) |
|
25.3.2.1 Overwriting Existing Data |
|
|
532 | (2) |
|
25.3.2.2 Appending a Text File |
|
|
534 | (2) |
|
25.3.3 Converting From String Characters |
|
|
536 | (1) |
|
25.3.4 Further Text Files |
|
|
536 | (2) |
|
25.3.4.1 CSV (Comma Separated Values) Files |
|
|
536 | (2) |
|
25.4 Working With Binary Files |
|
|
538 | (19) |
|
25.4.1 Saving & Retrieving Primitive Variables |
|
|
538 | (2) |
|
25.4.2 Saving & Retrieving Objects |
|
|
540 | (20) |
|
25.4.2.1 Working with Single Objects |
|
|
541 | (7) |
|
25.4.2.2 Working with an Array of Objects |
|
|
548 | (9) |
|
25.5 Further File Categories |
|
|
557 | (2) |
Part VII Generic Programming |
|
559 | (30) |
|
26 What is Generic Programming? |
|
|
560 | (4) |
|
|
560 | (4) |
|
26.1.1 Generic Thinking Outside the Programming World |
|
|
560 | (2) |
|
26.1.2 Generic Thinking Inside the Programming World |
|
|
562 | (3) |
|
26.1.2.1 Problems: Lack of Generics |
|
|
563 | (1) |
|
|
564 | (5) |
|
27.1 Creating Function Templates |
|
|
564 | (1) |
|
27.2 Instantiating Function Templates |
|
|
565 | (4) |
|
27.2.1 Compiler Generated Code |
|
|
567 | (7) |
|
27.2.1.1 Compiler Intelligence |
|
|
568 | (1) |
|
27.3 Polymorphism in Generic Programming |
|
|
569 | (1) |
|
|
569 | (9) |
|
28.1 Creating Class TEMPLATES |
|
|
570 | (2) |
|
28.2 Using Class Templates |
|
|
572 | (2) |
|
28.3 Template Parameters & Arguments |
|
|
574 | (2) |
|
28.3.1 Non-Type Template Parameters |
|
|
575 | (1) |
|
28.3.2 Template Template Parameters |
|
|
575 | (1) |
|
28.3.3 Default Template Arguments |
|
|
575 | (1) |
|
28.4 Class Template Design in UML |
|
|
576 | (1) |
|
28.5 Beauties of Generic Programming |
|
|
577 | (1) |
|
29 Template Specialisation & Overloading |
|
|
578 | (11) |
|
29.1 What is Template Specialisation |
|
|
578 | (1) |
|
29.2 Function Template Specialisation |
|
|
579 | (4) |
|
29.2.1 Implementing Function Template Specialisation |
|
|
579 | (4) |
|
29.3 Class Template Specialisation |
|
|
583 | (6) |
|
29.3.1 Explicit Specialisation |
|
|
583 | (2) |
|
29.3.2 Partial Specialisation |
|
|
585 | (4) |
Part VIII Getting It Together: Programming In C++ |
|
589 | (6) |
|
|
589 | (1) |
|
30.1 The Keyword "STATIC" |
|
|
589 | (1) |
|
30.2 The Keyword "VIRTUAL" |
|
|
590 | (1) |
|
|
590 | (1) |
|
31 Duplicate Symbols/Operators |
|
|
590 | (3) |
|
|
590 | (1) |
|
|
590 | (1) |
|
31.3 The Meanings of the = Symbol |
|
|
591 | (1) |
|
31.4 The Parentheses Operator 0 |
|
|
592 | (1) |
|
31.5 The Scope Resolution Operator :: |
|
|
592 | (1) |
|
|
593 | (1) |
|
|
593 | (1) |
|
|
594 | (1) |
Summary & Conclusions |
|
595 | (2) |
Appendix |
|
597 | (10) |
|
Appendix A: C++ Primitive Data Types |
|
|
598 | (1) |
|
Appendix B: C++ Operators |
|
|
599 | (7) |
|
Appendix C: Reserved Keywords In C++ |
|
|
606 | (1) |
Bibliography |
|
607 | (2) |
Index |
|
609 | (12) |
About The Author |
|
621 | |