Sunday, 1 September 2013

C++ Templates - specializing functions

C++ Templates - specializing functions

I have the following code:
//1
template<typename T>
void c(T in) {
cout << "Template c(" << in << ")" << endl;
}
//2
template<>
void c<>(int* in) {
cout << "Template specialization b(" << in << ")" <<endl;
}
//3
template<typename T>
void c(T* in) {
cout << "Template for pointers c(" << in << ")" <<endl;
}
//..
int i = 8;
c(&i);
Can someone explain me why in the following example compiler choose
function #3, but when I change the order of functions #2 and #3, then
compiler choose function #2?

No comments:

Post a Comment