Question: This program currently fails to compile. Modify TripleMin() so that item1 can be of a different type than item2 and item3. #include using namespace std;

This program currently fails to compile. Modify TripleMin() so that item1 can be of a different type than item2 and item3.

#include <iostream>
using namespace std;

template<typename TheType>
TheType TripleMin(TheType item1, TheType item2, TheType item3) {
TheType minVal = item1; // Holds min item value, init to first item

if (item2 < minVal) {
minVal = item2;
}
if (item3 < minVal) {
minVal = item3;
}

return minVal;
}

int main() {
int num1 = 55;
int num2 = 99;
int num3 = 66;
double dbl1 = 12.5;

cout << "Items: " << num1 << " " << num2 << " " << num3 << endl;
cout << "Min: " << TripleMin(num1, num2, num3) << endl << endl;

cout << "Items: " << dbl1 << " " << num2 << " " << num3 << endl;
cout << "Min: " << TripleMin(dbl1, num2, num3) << endl << endl;
 
return 0;
}

Step by Step Solution

3.51 Rating (144 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To solve this problem you need to modify the template function TripleMin so that item1 can be of a d... View full answer

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 Computer Network Questions!