久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

C++ typedef const 指針的解釋

C++ typedef interpretation of const pointers(C++ typedef const 指針的解釋)
本文介紹了C++ typedef const 指針的解釋的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

首先,示例代碼:

案例 1:


typedef char* CHARS;
typedef CHARS const CPTR;   // constant pointer to chars

文字替換CHARS變成:

Textually replacing CHARS becomes:


typedef char* const CPTR;   // still a constant pointer to chars

情況 2:


typedef char* CHARS;
typedef const CHARS CPTR;   // constant pointer to chars

文字替換CHARS變成:

Textually replacing CHARS becomes:


typedef const char* CPTR;   // pointer to constant chars

在情況 2 中,在文本替換 CHARS 后,typedef 的含義發生了變化.為什么會這樣?C++ 如何解釋這個定義?

In case 2, after textually replacing CHARS, the meaning of the typedef changed. Why is this so? How does C++ interpret this definition?

推薦答案

在文本替換的基礎上分析 typedef 行為是沒有意義的.類型定義名稱不是宏,它們不會被文本替換.

There's no point in analyzing typedef behavior on the basis of textual replacement. Typedef-names are not macros, they are not replaced textually.

正如你自己所說的

typedef CHARS const CPTR;

typedef const CHARS CPTR;

這是因為同樣的原因

typedef const int CI;

具有相同的含義

typedef int const CI;

Typedef-name 不定義新類型(僅是現有類型的別名),但它們在某種意義上是原子的",任何限定符(如 const)都適用于最頂層,即它們適用于隱藏在 typedef-name 后面的整個類型.一旦你定義了一個 typedef-name,你就不能在其中注入"一個限定符來修改任何更深層次的類型.

Typedef-name don't define new types (only aliases to existing ones), but they are "atomic" in a sense that any qualifiers (like const) apply at the very top level, i.e. they apply to the entire type hidden behind the typedef-name. Once you defined a typedef-name, you can't "inject" a qualifier into it so that it would modify any deeper levels of the type.

這篇關于C++ typedef const 指針的解釋的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Difference between std::reference_wrapper and simple pointer?(std::reference_wrapper 和簡單指針的區別?)
Difference between const. pointer and reference?(常量之間的區別.指針和引用?)
How to access the contents of a vector from a pointer to the vector in C++?(c++ - 如何從指向向量的指針訪問向量的內容?)
Meaning of *amp; and **amp; in C++(*amp; 的含義和**amp;在 C++ 中)
Why can#39;t I do polymorphism with normal variables?(為什么我不能對普通變量進行多態?)
Dereferencing deleted pointers always result in an Access Violation?(取消引用已刪除的指針總是會導致訪問沖突?)
主站蜘蛛池模板: 91免费视频 | 亚洲一区二区在线播放 | 蜜桃视频一区二区三区 | 欧美精品综合在线 | 久久精品日 | 亚洲日韩中文字幕一区 | 精品国产伦一区二区三区观看说明 | 国产一级片精品 | 午夜三区 | 欧美午夜一区 | 草久久久| 黄视频欧美 | 中文字幕在线观看www | 亚洲成人一区 | 国产精品不卡一区 | 国产免费一区二区 | 成人精品一区二区三区中文字幕 | 91免费观看| 欧美日本韩国一区二区三区 | 午夜资源 | 精品视频一区二区 | 可以免费观看的av | 国产精品久久久久aaaa | 国产精品免费一区二区三区四区 | 久久一区二区三区免费 | 色视频网站在线观看 | 伊人狠狠操| 国产高清视频一区二区 | 亚洲一区 中文字幕 | 午夜三区 | 精品一区国产 | 91伊人| 亚洲国产一 | 黄色一级大片在线免费看产 | 国产精品日韩欧美一区二区三区 | 亚洲码欧美码一区二区三区 | 亚洲国产精品99久久久久久久久 | av在线天堂网 | 一区二区三区电影网 | 中文字幕在线电影观看 | 三级黄片毛片 |