O'Reilly logo

Advanced Metaprogramming in Classic C++ by Davide Di Gennaro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required