”工欲善其事,必先利其器。“—孔子《论语.录灵公》
首页 > 编程 > 以下是根据您提供的文章内容生成的英文问答类标题: Why does `char` behave differently from integer types in template instantiation when comparing `char`, `signed char`, and `unsigned char`?

以下是根据您提供的文章内容生成的英文问答类标题: Why does `char` behave differently from integer types in template instantiation when comparing `char`, `signed char`, and `unsigned char`?

发布于2024-11-03
浏览:217

以下是根据您提供的文章内容生成的英文问答类标题:

Why does `char` behave differently from integer types in template instantiation when comparing `char`, `signed char`, and `unsigned char`?

char、signed char 和 unsigned char 之间的行为差​​异

下面的代码可以成功编译,但 char 的行为与整数类型不同。

cout ::ikIsX  >() ::ikIsX  >() ::ikIsX  >() 

结果是三种类型的三种实例化模式:int8、uint8 和 char。为什么会发生这种情况?

对于整数则不然: int 和 uint32 导致一种模式实例化,而signed int 导致另一种模式实例化。

原因可能是因为 C 对待 char ,有符号字符和无符号字符作为三种不同的类型。而 int 与signed int 相同。这是真的吗,还是我遗漏了什么?

#include 

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 
struct isX
{
   typedef typename T::ikIsX ikIsX;
};


// Это  int==int32 неоднозначно
//template  bool getIsTrue();
template ::ikIsX  >() ::ikIsX  >() ::ikIsX  >() ::ikIsX  >() ::ikIsX  >() ::ikIsX  >() 

我用 g 4.something

最新教程 更多>

免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。

Copyright© 2022 湘ICP备2022001581号-3