In the code below, why do the two ways of invoking fun
: fun(num)
and fun<const int>(num)
, give a different result when compiling?
#include <iostream>
using namespace std;
template<typename T, typename = typename enable_if<!std::is_same<int, T>::value>::type>
void fun(T val)
{
cout << val << endl;
}
int main(void)
{
const int num = 42;
fun(num); //ERROR!
fun<const int>(num); //Right
return 0;
}
int
prvalue is never const qualified. – Fronde