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

混合類和結構

Mixing class and struct(混合類和結構)
本文介紹了混合類和結構的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我很清楚class 和 struct 之間的區別,但是我很難權威地說這是否定義明確:

I'm well aware of the difference between class and struct, however I'm struggling to authoritatively say if this is well defined:

// declare foo (struct)
struct foo;

// define foo (class)
class foo {
};

// instance of foo, claiming to be a struct again! Well defined?
struct foo bar;

// mixing class and struct like this upsets at least one compiler (names are mangled differently)
const foo& test() {
   return bar;
}

int main() {
   test();
   return 0;
}

如果這是未定義的行為,有人可以指出我權威(即 ISO 中的章節和詩句)參考的方向嗎?

If this is undefined behaviour can someone point me in the direction of an authoritative (i.e. chapter and verse from ISO) reference?

編譯器在處理此問題時遇到問題(Carbide 2.7)相對較舊,我嘗試過的所有其他編譯器都對此非常滿意,但顯然這并不能證明任何事情.

The compiler with problems handling this (Carbide 2.7) is relatively old and all the other compilers I've tried it on are perfectly happy with this, but clearly that doesn't prove anything.

我的直覺是這應該是未定義的行為,但我找不到任何可以證實這一點的東西,我很驚訝 GCC 版本或 Comeau 已經警告過了.

My intuition was this ought to be undefined behaviour but I can't find anything to confirm this and I'm surprised that none of the GCC versions or Comeau so much as warned about it.

推薦答案

在我看來,它像是已定義的行為.特別是,§9.1/2 說:

It looks to me like it's defined behavior. In particular, §9.1/2 says:

僅由 class-key identifier ; 組成的聲明要么是對當前作用域中的名稱或標識符的前向聲明作為類名.它將類名引入當前作用域.

A declaration consisting solely of class-key identifier ; is either a redeclaration of the name in the current scope or a forward declaration of the identifier as a class name. It introduces the class name into the current scope.

標準在定義一個類時區分使用classstructunion,但在這里,談論關于聲明,沒有這樣的區別——使用一個 class-key 等同于任何其他.

The standard distinguishes between using class, struct or union when defining a class, but here, talking about a declaration, no such distinction is made -- using one class-key is equivalent to any other.

這篇關于混合類和結構的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數據?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環: for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環?)
Reusing thread in loop c++(在循環 C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環形?)
主站蜘蛛池模板: 国产精品成人一区二区三区夜夜夜 | 亚洲第1页 | 精品一区二区三区在线视频 | 欧美一区二区三区在线播放 | 精品少妇一区二区三区在线播放 | 在线观看www | 91精品欧美久久久久久久 | 亚洲色图在线观看 | 精区3d动漫一品二品精区 | 国产精品精品久久久久久 | 一区二区三区四区不卡视频 | 欧美成人a∨高清免费观看 欧美日韩中 | 日本久久久久久 | 久久久国产一区 | 亚洲国产成人在线视频 | 综合精品| av一级久久 | 999久久久久久久久6666 | 久久精品国产久精国产 | 韩国av一区二区 | 99视频久| 欧美激情精品久久久久久 | 久久黄色网| 成人福利在线观看 | 天堂一区| 黄色片视频免费 | 中文字幕一区二区三区四区 | 7799精品视频天天看 | 日本超碰| 国产精品久久 | 99婷婷| 国产精品精品久久久久久 | 欧美日韩一区二区电影 | 欧美美女被c | 一级黄色裸片 | 久久爱一区 | 日韩高清中文字幕 | 国产福利在线视频 | av网站在线看 | 国产视频久久 | 久久精品99久久 |