Saturday, January 28, 2006

template specialization

If you want to test whether someone has understood how template specialization works is the following which is derived from a famous example by Peter Dimov and Dave Abrahams. So let's test you!

What's the return value of the function g in the following code? Explain your opinion!

template<typename T> int f(T) { return 1; }
template<> int f<>(int*) { return 2; }
template<typename T> int f(T*) { return 3; }
int g(int* i) { return f(i); }

No comments: