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

混合類和結(jié)構(gòu)

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

問題描述

我很清楚class 和 struct 之間的區(qū)別,但是我很難權(quán)威地說這是否定義明確:

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;
}

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

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

編譯器在處理此問題時(shí)遇到問題(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.

我的直覺是這應(yīng)該是未定義的行為,但我找不到任何可以證實(shí)這一點(diǎn)的東西,我很驚訝 GCC 版本或 Comeau 已經(jīng)警告過了.

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 ; 組成的聲明要么是對當(dāng)前作用域中的名稱或標(biāo)識符的前向聲明作為類名.它將類名引入當(dāng)前作用域.

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.

標(biāo)準(zhǔn)在定義一個(gè)類時(shí)區(qū)分使用classstructunion,但在這里,談?wù)撽P(guān)于聲明,沒有這樣的區(qū)別——使用一個(gè) 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.

這篇關(guān)于混合類和結(jié)構(gòu)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數(shù)據(jù)?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環(huán): for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環(huán)?)
Reusing thread in loop c++(在循環(huán) C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環(huán)形?)
主站蜘蛛池模板: 久久性av | 欧美精品久久久 | 欧美久久久久久久久中文字幕 | www.免费看片.com | 玖玖国产 | 视频一区二区在线观看 | 亚洲欧美久久 | 日韩免费中文字幕 | 日韩无| 日韩精品一区二区三区在线播放 | 欧美a级成人淫片免费看 | 国产精品亚洲成在人线 | 国精品一区二区 | 狠狠插天天干 | 一区二区三区国产 | 国产精品综合色区在线观看 | 超碰3 | 欧美mv日韩mv国产网站91进入 | a欧美| 久久久久国产一区二区三区 | 久草热8精品视频在线观看 午夜伦4480yy私人影院 | 国产亚洲一区二区三区在线观看 | 逼逼网 | 欧美久久久久久久久 | 亚洲视频在线观看 | 精品久久国产 | 成人av片在线观看 | 天天噜天天干 | 久久精品国产一区二区三区 | 成人免费视频网站在线看 | 亚洲第一av | 欧美视频成人 | 伊人久久精品 | 免费黄色a级毛片 | 国产一二三区免费视频 | 午夜视频免费网站 | 日韩精品视频一区二区三区 | 中文字幕亚洲视频 | 午夜欧美日韩 | 在线观看中文字幕视频 | 国产精品日韩欧美一区二区三区 |