§14.8.2/4 allows the instantiation of two different functions, g<int>
and g<const int>
from the template definition. Why doesn't the Standard allow the definition of the two functions f
in the code below? I know that both functions would have the same type void(int)
. But that also happens with the instantiated functions g
. The note in §14.8.2/4 says: f<int>(1) and f<const int>(1) call distinct functions even though both of the functions called have the same function type.
.
#include <iostream>
template<typename T>
void g(T t) { std::cout << t << '\n'; }
void f(int i) { std::cout << i << '\n'; }
//void f(int const i) { std::cout << i << '\n'; } // doesn't compile
int main()
{
g<int>(1);
g<int const>(2);
}