」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 以下是根據您提供的文章內容產生的英文問答類標題: 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
瀏覽:653

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

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