Qorn Qorn - 1 month ago 29
C++ Question

What is the diference between template call?

What is the difference between A, B and C calls?

#include <iostream>

using namespace std;

template<class T> T max(T a, T b) {
return (a >= b) ? a : b;

int main() {
float a = 4.0;
float b = 6.0f;
cout << max(a, b) << endl; //A
cout << max<double>(a, b) << endl; //B
cout << max<double>(4.0, 6.0f) << endl; //C


First invocation of max is actually max<float>, second and third is the same max<double>

But in second invocation both a and b got promoted to double, where is in third example only 6.0f is got promoted to double.