下面的代码编译,但char类型的行为与int类型的行为不同.
特别是
cout << getIsTrue< isX<int8>::ikIsX >() << endl;
cout << getIsTrue< isX<uint8>::ikIsX >() << endl;
cout << getIsTrue< isX<char>::ikIsX >() << endl;
Run Code Online (Sandbox Code Playgroud)
导致三种类型的模板的3个实例化:int8,uint8和char.是什么赋予了?
对于ints来说也是如此:int和uint32导致相同的模板实例化,而signed int则是另一个.
原因似乎是C++将char,signed char和unsigned char视为三种不同的类型.而int与signed int相同.这是对的还是我错过了什么?
#include <iostream>
using namespace std;
typedef signed char int8;
typedef unsigned char uint8;
typedef signed short int16;
typedef unsigned short uint16;
typedef signed int int32;
typedef unsigned int uint32;
typedef signed long long int64;
typedef unsigned long long uint64;
struct TrueType {};
struct FalseType {};
template <typename T>
struct isX …Run Code Online (Sandbox Code Playgroud)