Can you please explain to me how exactly can I make a generic compare function?
template
bool compare(T a, T b)
{
//what will come here when I want to return a > b
}
Can you please explain to me how exactly can I make a generic compare function?
template
bool compare(T a, T b)
{
//what will come here when I want to return a > b
}
hello @shivangi99
template < typename T >
bool compare(T a, T b){
return a > b ; // compiler will automatically compare as per their datatype
}
if u want to compare any objects then in that case u need to add overloading code for ur operator > for that class
check this example ->
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.