#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? –