Originally Posted by
laserlight
Because I do not expect T = const int.
Ah! You're right!
I can see it with this code:
Code:
template <typename T>
void foo(T t) { t.Fail(); }
int main()
{
const int x = 3;
foo(x);
return 0;
}
Code:
constT.cpp: In function ‘void foo(T) [with T = int]’:
constT.cpp:7: instantiated from here
constT.cpp:2: error: request for member ‘Fail’ in ‘t’, which is of non-class type ‘int’
That seems really weird to me though. I'm used to thinking about 'const' as being part of the type, I mean you can do overloads based on constness and also typedefs:
Code:
template <typename T>
void foo(T t) { t.Fail(); }
typedef const int cint;
int main()
{
cint x = 3;
foo(x); // (only error in this program is the same one from here)
return 0;
}
Naturally, I expected that the compiler would see a request for void foo(const int&) and match it using [T = const int].