10.15. Exercises

1: Provide another Stack constructor that builds Stack objects and initializes them with generic data (see Listing 10.1 on page 415). Test your solution with different data types.
2:Redesign the template Stack class (page 415) to contain class Array. Do you need the full boilerplate?
3:Implement a resize() member function for class Array. Devise a strategy to implement resize() for Array2d. Can you reuse resize() from your Array class?
4:Explain why the template Block class from Listing 10.15 on page 441 is a better design approach than a template function that allocates memory for generic arrays and initializes each element. Consider the following examples with template function new_data().
 int ival = 0; String sval = "abc"; int ...

Get Navigating C++ and Object-Oriented Design 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.