In your clone of this repository, find the 5-templates
exercise. It contains two sub-directories part1
and part2
.
List the files in part1
:
$ cd archer2-cpp/exercises/5-templates/part1
$ ls
Makefile sum.cpp
sum.cpp
. Do you think it will compile? If so, what will the output be?make && ./sum
. Is the result what you expected? Can you explain what is happening at line 12?
11 sum(3, 4);
12 sum(3.2, 5.1);
13 // sum("Hello", "World!");
sum()
function to use type templating. How does this change the output? Hint: C++ will not automatically convert from a char array to std::string so you will need to be explicit.List the files in part2
:
$ cd archer2-cpp/exercises/5-templates/part2
$ ls
Makefile complex.cpp complex.hpp test.cpp
complex.cpp
contains a working version of the complex number class. Change the class declaration and definitions to use type templating.