11.10 — Using function templates in multiple files

Consider the following program, which doesn’t work correctly: main.cpp: #include <iostream> template <typename T> T addOne(T x); // function template forward declaration int main() { std::cout << addOne(1) << ‘\n’; std::cout << addOne(2.3) << ‘\n’; return 0; } add.cpp: template <typename T> T addOne(T x) // function template definition { …

13.5 — Introduction to overloading the I/O operators

In the prior lesson (), we showed this example, where we used a function to convert an enumeration into an equivalent string: #include <iostream> #include <string_view> enum Color { black, red, blue, }; constexpr std::string_view getColorName(Color color) { switch (color) { case black: return “black”; case red: return “red”; case …