#include <iostream>
template<typename T, int = 0>
struct test {
typedef char type[3];
};
template<int N>
struct test<long *, N> {
typedef char type[7];
};
int main()
{
std::cout << sizeof( test<int*>::type ) << std::endl; // 3
std::cout << sizeof( test<long*>::type ) << std::endl; // 7
return 0;
}
I expected sizeof( test<long*>::type ) == 3. Why it is 7?
What you did is you specialized the template, saying that whenever the type argument is
long*, you should use the second form of the template. For other arguments, it will use the initial form of the template (with size 3).