Question: Let's say you have a function int calc (int operand1, int operand2, char op) where op is either'+' or. Instead of overloading this function for

 Let's say you have a function int calc (int operand1, int

Let's say you have a function int calc (int operand1, int operand2, char op) where op is either'+' or. Instead of overloading this function for each numerical datatype in C++ (e.g. also defining it for float, double, etc., you want to create a generic function that is far more flexible. In the space below, define calc as a template function. If op is neither '+' nor '-', print an error message on cerr and call the system function exit (1); (you may assume that #include has already been done.) Note that once we've covered exceptions, that would be a better approach than the cerr/exit technique. Grading: for correct template function header for correctly handling the error for function body being correct for non-error case

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!