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

是“一過即盡"嗎?非數組類型的指針是 C++ 中

Is the quot;one-past-the-endquot; pointer of a non-array type a valid concept in C++?(是“一過即盡嗎?非數組類型的指針是 C++ 中的有效概念嗎?)
本文介紹了是“一過即盡"嗎?非數組類型的指針是 C++ 中的有效概念嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

C++ 標準 [sec 5.7] 說:

The C++ standard [sec 5.7] says:

如果指針操作數和結果都指向同一個數組對象的元素,或者一個過去數組對象的最后一個元素,求值不應產生溢出;否則,行為是未定義.

If both the pointer operand and the result point to elements of the same array object, or one past the last element of the array object, the evaluation shall not produce an overflow; otherwise, the behavior is undefined.

那么,我是否正確地假設數組以外的其他類型的指針未定義?

So, am I correct in assuming that pointers one-past-the-end of other types than arrays are undefined?

例如:

int a = 0;
vector<int> v(&a, (&a)+1);

上面的代碼片段編譯并運行得很好(使用 g++),但它有效嗎?

The above snippet compiles and works just fine (with g++), but is it valid?

推薦答案

不,這是合法的.5.7(4) - 您引用前的一段 - 說:就這些運算符而言,指向非數組對象的指針的行為與指向長度為 1 的數組的第一個元素,以對象的類型作為其元素類型."

No, it is legal. 5.7(4) - one paragraph before your quote - says: "For the purposes of these operators, a pointer to a nonarray object behaves the same as a pointer to the first element of an array of length one with the type of the object as its element type."

這篇關于是“一過即盡"嗎?非數組類型的指針是 C++ 中的有效概念嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 | 日本福利在线 | 亚洲欧美另类在线观看 | 亚洲视频免费观看 | 日韩av一区二区三区四区 | 日韩1级片 | 一级欧美一级日韩 | 每日更新av | 丁香婷婷六月天 | 五月婷婷六月激情 | av福利在线观看 | 国产色在线 | 欧美一区二区三区在线观看 | 日韩精品中文字幕在线观看 | 一区两区小视频 | 国产91精品在线观看 | 欧美日韩一区二区在线 | 一级a毛片 | 在线不卡一区 | 男人的天堂在线视频 | 一级特黄毛片 | 日韩一级二级三级 | 在线亚洲精品 | 久久精品在线观看 | 黄色欧美视频 | 一本久| 日韩有码av| 天天色天天干天天 | 亚洲亚洲人成综合网络 | 精品久久久久久 | 欧美一区在线视频 | 日韩av免费在线 | 欧美一区二区三区视频 | 黄色www| 91亚洲精品在线 | 国产精品视频免费看 | 99超碰在线观看 | 国产xxx| 午夜美女福利 | www在线播放| www.jiujiu |