Question: C++ Write a template function add that takes in two arguments and produces the result of the addition. It should be able to add two
C++
Write a template function add that takes in two arguments and produces the result of the addition. It should be able to add two integers, doubles, and floats with one function. Here is the test code and the expected output:
#includeusing namespace std; // Put the add function here int main() { cout << "The result of 2 + 2 is " << add (2, 2) << endl; cout << "The result of 3.14 + 0.0015 is " << add (3.14f, 0.0015f) << endl; cout << "The result of -2.1 + 13.9 is " << add (-2.1, 13.9) << endl; return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
