Chapter 38. Typedef

Difficulty: 3

Why use typedef? Besides the many traditional reasons, we'll consider typedef techniques that make using the C++ standard library safer and easier.

  1. Why use typedef? Name as many situations/reasons as you can.

  2. Why is typedef such a good idea in code that uses standard (STL) containers?

Solution

Solution

Typedef: Controlling What's in a Name

To recap, writing typedef allows you to assign another equivalent name for a type. For example,

typedef vector< vector<int> > IntMatrix;

lets you write the simpler IntMatrix in place of the more verbose vector< vector<int> >.

  • 1. Why use typedef? Name as many situations/reasons as you can.

Here ...

Get More Exceptional C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.