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

是“內聯"嗎?隱含在類定義中定義的 C++ 成員

Is quot;inlinequot; implicit in C++ member functions defined in class definition(是“內聯嗎?隱含在類定義中定義的 C++ 成員函數中)
本文介紹了是“內聯"嗎?隱含在類定義中定義的 C++ 成員函數中的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

根據 C++ 規范,以下兩個類是否等價定義?

According to the C++ specification, are the following two classes equivalently defined?

class A
{
   void f()
   {
   }
};

class B
{
   inline void f()
   {
   }
};

即,將內聯"限定符放在類定義中定義的此類成員函數上是否完全多余?

i.e., is putting the "inline" qualifier on such member function defined in the class definition completely redundant?

后續問題:假設它是多余的,對于代碼風格,保留內聯"標簽是否明智,因此未來的開發人員意識到應該內聯該函數,并且不會刪除其他地方的定義并刪除內聯?

Followon question: Assuming it is redundant, for code style, would it be sensible to keep the "inline" tag, so a future developer realises that function should be inlined, and does not remove the definition somewhere else and remove the inlining?

謝謝:)

推薦答案

它們是等價的類定義,除了單一定義規則的用途.所以標準不保證你可以用一個類定義編譯一個 TU(翻譯單元),用另一個編譯一個不同的 TU,然后將它們鏈接在一起.我懷疑這是否會在真正的實現中失敗,但這就是標準所說的.

They're equivalent class definitions except for the purposes of the One Definition Rule. So the standard does not guarantee that you can compile one TU (translation unit) with one class definition and a different TU with the other, and then link them together. I doubt that this would ever actually fail on a real implementation, but that's what the standard says.

inline 關鍵字幾乎與內聯無關.這是關于在不同的 TU 中是否允許函數的多個相同定義.如果有人把函數定義移到別處,那么他們應該根據以下基礎決定是否標記它inline:

The inline keyword has approximately nothing to do with inlining. It's about whether multiple identical definitions of the function are permitted in different TUs. If someone moves the function definition elsewhere, then they should decide whether to mark it inline on the following basis:

  • 如果它在該類的 .cpp 文件中,那么如果它僅從該 TU 調用,則將其標記為 inline 是有效的.那么它是否標記為 inline 可能沒有區別,但是如果您認為編譯器會注意您的內容,則可以將其標記為 inline 作為編譯器提示想要.

  • If it is in a .cpp file for that class, then it's valid to mark it inline if it's called only from that TU. Then it probably makes no difference whether it is marked inline or not, but you could mark it inline as a compiler hint if you think the compiler will pay any attention to what you want.

如果它仍在頭文件中,則必須將其標記為inline,否則在鏈接使用該頭文件的不同 TU 時會出現多個定義錯誤.

If it is still in the header file, then it must be marked inline, or else you'll get multiple definition errors when linking different TUs that use the header.

假設移動函數的人知道那些東西,我認為他們不需要在類定義中提醒.如果他們不知道這些事情,那么他們可能無法移動該函數,但對他們來說,使用 inline 關鍵字來移動它會更安全.

Assuming that the person moving the function knows those things, I don't think they need a reminder in the class definition. If they don't know those things, then they probably have no business moving the function, but it would be safer for them to have an inline keyword to move with it.

這篇關于是“內聯"嗎?隱含在類定義中定義的 C++ 成員函數中的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Assertion failed (size.widthgt;0 amp;amp; size.heightgt;0)(斷言失敗(size.width0 amp;amp; size.height0))
Rotate an image in C++ without using OpenCV functions(在 C++ 中旋轉圖像而不使用 OpenCV 函數)
OpenCV: process every frame(OpenCV:處理每一幀)
Why can#39;t I open avi video in openCV?(為什么我不能在 openCV 中打開 avi 視頻?)
OpenCV unable to set up SVM Parameters(OpenCV 無法設置 SVM 參數)
Convert a single color with cvtColor(使用 cvtColor 轉換單一顏色)
主站蜘蛛池模板: 夜夜骚 | 国产精品特级毛片一区二区三区 | 99re在线视频| 日本一区二区三区视频在线 | 精品二区 | 欧美一级在线观看 | 51ⅴ精品国产91久久久久久 | va精品| 国产精品www | 国产精品久久久久久久久久免费看 | 国产精品a一区二区三区网址 | 青青草原综合久久大伊人精品 | 久久国产精品91 | 国产精品久久久久久久久久 | 日韩久久久久久久 | 蜜桃传媒av | 99久久精品免费看国产小宝寻花 | 国产精品国产a级 | 成人性视频免费网站 | 精精国产xxxx视频在线播放 | 国产精品无 | 91在线免费观看网站 | 黄色小视频大全 | 999久久久 | 黑人巨大精品欧美黑白配亚洲 | 亚洲欧美一区二区三区1000 | 日韩精品一区二区三区中文在线 | 久草精品视频 | 欧美激情视频网站 | 欧美一级黄色片免费观看 | 99精品国产一区二区青青牛奶 | 成人网址在线观看 | 97国产精品视频人人做人人爱 | 国产高清自拍视频在线观看 | 精品一区二区三区不卡 | 久久三区 | 青青草视频免费观看 | 欧美久久久久久 | 中文字幕一区二区三区不卡在线 | 欧美成人一级视频 | 男女羞羞视频大全 |