#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;
}
我预计sizeof(test<long*>::type) == 3
。为什么是7?模板类型的奇怪行为
你为什么期望它是3? –