APPENDIX A

image

Exercises

A.1. Exercises

In all the following problems, the reader should assume that a single writable file with some template code is given; more files can be added, and the rest of the project is read-only.

A.1.1. Extension

A function template is given:

template <typename T>void f(T x){   printf("hello T");}
  • Add another overload that is to be called for every class that derives from BASE and prints “hello BASE-or-derived”
  • Ensure that your solution is robust. Change the return type of f to int and see if your solution still holds
  • Ensure that your solution is robust. Add a plain function – say int f(double x) – in the same file and ...

Get Advanced Metaprogramming in Classic 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.