< Previous | Contents | Next >

R

rand()function, 69–70 random numbers, generating,

68–72

calculating number within range, 71–72

Die Roller program, 68–69

rand()function, 69–70

seeding, 70–71

random_shuffle() algorithm, 134–135, 143

random-element access, 147

rank m_Rank member, BlackJack

Card class, 359

reallocation, vector memory, 136 reassigning pointers, 229

redundant parentheses, 68 reference operator (&),

189, 217

references, 187–217

versus constant pointers, 232 creating, 189–190

deciding how to pass arguments, 198

defined, 217 passing

to alter arguments, 191–194 constant references,

197–198

Inventory Displayer pro- gram, 195–196

pitfalls, 196–197

versus pointers, 249

Referencing program, 187–189

returning, 198–203

altering object through, 202 assigning to reference, 202 assigning to variable, 202 displaying value of, 201 Inventory Referencer

program, 199–200

overview, 200–201

Tic-Tac-Toe game, 203–217 announceWinner() function, 217

askNumber()function, 209


askYesNo()function, 208–209

computerMove()function, 213–216

creating list of functions, 205

displayBoard()function, 210–211

humanMove()function, 213

humanPiece()function, 209–210

instructions()function, 208

isLegal()function, 212–213

main()function, 207–208

opponent()function, 210

pseudocode, 204

representing data, 204–205

setting up, 205–207

winner()function, 211–212 values

accessing, 190

altering, 190–191

Referencing program, 187–189

refToElement() function header, 200–201, 240

relational operators, 40tbl, 44

reserve()member function, 137

restricting pointers, 243, 251

return statement, 50, 158,

184–185

return type, constructor, 262 return values, function, 157–158

return statement, 158 specifying return type, 157 using, 158

returning pointers, 238–244

altering object through, 243–244

assigning to pointer, 242 assigning to variable value

pointed to by returned pointer, 242–243

Inventory Pointer program, 239–240

overview, 240–241

using to display value, 241–242

returning references, 198–203, 220 altering object through, 202 assigning, 202

assigning to reference, 202 assigning to variable, 202 displaying value of, 201 Inventory Referencer program,

199–200

overview, 200–201

408 Index


reusability, class, 332–333 role-playing game (RPG), 72 run-time errors, 4