久久久久久久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 轉換單一顏色)
主站蜘蛛池模板: 久久亚洲精品视频 | 精品一区二区三区在线观看国产 | 成人欧美 | 亚洲一区中文 | 美女视频黄色片 | 午夜免费网站 | 国产三区在线观看视频 | 91在线网站 | 日本欧美黄色片 | 中文字幕亚洲区一区二 | 九九热精品在线 | 国产高清在线视频 | 久操亚洲| 99re国产 | 精品九九在线 | 成人欧美一区二区三区色青冈 | 日韩精品三区 | 精品欧美一区二区三区免费观看 | 亚洲一区二区日韩 | 国产精品国产三级国产aⅴ无密码 | 日韩在线精品强乱中文字幕 | 日韩无| 男女性毛片 | 九九热免费观看 | 2019天天操| 亚洲久久一区 | 天天草夜夜骑 | 一区二区三区视频在线 | 三级在线免费 | 亚洲网站在线观看 | 久精品久久 | 亚洲成人午夜电影 | 国产高清精品在线 | 亚洲精品二三区 | 精品国产不卡一区二区三区 | 成人av片在线观看 | 国产精品久久久久久久久久久久久久 | 国产精品一区二区在线 | 罗宾被扒开腿做同人网站 | 99热这里有精品 | caoporn国产精品免费公开 |