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

類聲明大括號后的分號

Semicolon after class declaration braces(類聲明大括號后的分號)
本文介紹了類聲明大括號后的分號的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

在 C++ 類中,為什么右大括號后面有分號?我經常忘記它并得到編譯器錯誤,因此浪費了時間.對我來說似乎有些多余,事實并非如此.人們真的會做這樣的事情嗎:

In C++ classes, why the semi-colon after the closing brace? I regularly forget it and get compiler errors, and hence lost time. Seems somewhat superfluous to me, which is unlikely to be the case. Do people really do things like:

class MyClass
{
.
.
.
} MyInstance;

我是從結構和枚舉的 C 兼容性的角度來理解它的,但是由于類不是 C 語言的一部分,我猜它主要是為了保持類似聲明結構之間的一致性.

I get it from a C compatibility point of view for structs and enums, but since classes aren't part of the C language I guess it's primarily there the keep consistency between similar declaration constructs.

我正在尋找更多與設計原理相關的東西,而不是能夠改變任何東西,盡管一個好的代碼完成 IDE 可能會在編譯之前捕獲它.

What I was looking for was more related to design rationale rather than being able to change anything, although a good code completion IDE might trap this before compilation.

推薦答案

語言需要類型聲明中右大括號后的分號.從最早的 C 版本開始就是這樣.

The semi-colon after the closing brace in a type declaration is required by the language. It's been that way since the earliest versions of C.

是的,人們確實會執行您剛才在那里發表的聲明.它對于在方法內部創建作用域類型很有用.

And yes, people do indeed do the declaration you just put up there. It's useful for creating scoped types inside of methods.

void Example() {
  struct { int x; } s1;
  s1.x = 42;

  struct ADifferentType { int x; };
}

在這種情況下,我認為很清楚為什么需要分號.至于為什么在更一般的情況下需要在頭文件中聲明,我不確定.我的猜測是它是歷史性的,并且是為了讓編寫編譯器更容易.

In this case, I think it's clear why the semi-colons are needed. As to why it's needed in the more general case of declaring in the header file I'm unsure. My guess is that it's historical and was done to make writing the compiler easier.

這篇關于類聲明大括號后的分號的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 ()?環形?)
主站蜘蛛池模板: 免费国产精品视频 | 一级特黄妇女高潮 | 日韩视频免费大全中文字幕 | 婷婷91 | 999毛片 | 成人免费看片39 | 黄色免费片 | 免费毛片基地 | 亚洲福利视频一区 | 久久久久久久九九九九 | 日本精品在线视频 | 欧美精品一区二区三区四区 | 久久一区 | 日韩一区二区三区视频 | 成人在线免费视频 | 日韩成人在线播放 | 亚洲成a人| 一级黄色片免费 | 精品在线免费视频 | 国产精品美女久久久 | 日韩影院在线观看 | 成人在线播放视频 | 精品国产欧美 | 亚洲国产成人精品女人久久久 | 又色又爽又黄18网站 | 亚洲免费网站 | 国产不卡在线视频 | 欧美视频一区二区 | 久久九九免费视频 | 日韩精品中文字幕在线观看 | 色综合一区 | 饥渴放荡受np公车奶牛 | 中文字幕理论片 | 日韩亚洲欧美在线观看 | 日本毛片在线观看 | 国产精品国产精品国产专区不片 | 国产成人免费在线视频 | 免费a视频 | 天天干天天草 | 97成人在线 | 亚洲天堂av网 |