Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Dev C++ 4.9.9.2 Ep1022TAM1-p1022TAM dev File Edit Search View Project Execute De

ID: 3819132 • Letter: D

Question

Dev C++ 4.9.9.2 Ep1022TAM1-p1022TAM dev File Edit Search View Project Execute Debug Tools cs window Help Lau Toggle Golo Project Classes Debug max hall IP1022TAM.cpp minh //definition of template minimum template colas 8 T> men h T min (T value1,T value2) P1022 TAM cpp T minValue if (value1 value2) value1: minValue else value2 minValue return minvalue; EB Compiler Resources db compie Logl Debugla Find Results 3 cose Message Line In function nt man0 E:VP1022TAMVP1022TAM.cpp ini&T; is ambiguous E:VP1022TAMVP1022 TAM cpp candidates are T minNTT) Milh T. Tp.std streamsizel const Tp& stdt minconst Tpl, const Tpl)(with ote E. P1022TAMVminaha4 EMP1022TAM min h 4 [Build Errorl (P1022TAM ol Enor 1 EVP1022TAM'Makelile wn

Explanation / Answer

Template is an more abstract level of a Class by allowing more than one type of data types to be handled by a same class without the need for the definition of more classes.A template class can handle integers,characters,strings etc.For example you can check if a character is greater that a character or an integer is greater than an integer by using a same template class. After observing above implementation I reached to a conclusion that specification of datatype during calling of function is missing min<int>(v1,v2) . If we call it directly then it will give ambiguity error in code.So, it is must to place datatype during generics call.

corrected code:-
#include<iostream.h>
#include<stdio.h>
#include<conio.h>

using namespace std;

template<class T>
T min(T n1,T n2)
{
if(n1<n2)
return n1;
else if(n1>n2)
return n2;
else
cout<<"EQUAL";
}
int main()
{
int a=1,b=5;
cout<<"The minimum value fpr the integers(1,5) is : "<< min<int>(a,b) << endl;
return 0;
}