< Previous | Contents | Next >

Using a Returned Pointer to Display a Value

After I create inventory, a vector of items, I display a value with a returned pointer.

cout << *(ptrToElement(&inventory, 0)) << "\n\n";

The preceding code calls ptrToElement(), which returns a pointer to inventory[0]. (Remember, ptrToElement() doesnt return a copy of one of the elements of

242 Chapter 7 n Pointers: Tic-Tac-Toe 2.0


inventory; it returns a pointer to one of them.) The line then sends the string

object pointed to by the pointer to cout. As a result, sword is displayed.