簡體   English   中英

為什么雙參數構造函數以顯式關鍵字開頭?

[英]Why double parameter constructor begins with an explicit keyword?

我的好友和我最近一直在閱讀leveldb源代碼。 我們遇到了這個問題。 在leveldb db / skiplist.h文件中,有一個構造函數聲明:

explicit SkipList(Comparator cmp, Arena* arena);

我知道帶有單個參數的顯式構造函數意味着沒有構造函數參數的隱式類型轉換。 但是具有顯式關鍵字的雙參數構造函數意味着什么? 這是C ++ 11的新規則嗎?

謝謝。

使用C ++ 11,您可以使用braced-init-lists代替其他一些表達式,這會產生影響。 例如,您可以在return語句中使用它們:

SkipList foo() {
    return {{}, nullptr}; //does not compile with explicit constructor
    return SkipList{{}, nullptr}; //compiles with or without explicit constructor
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM