为什么双参数构造函数以显式关键字开头



我和我的好友最近一直在阅读leveldb源代码。我们遇到了这个问题。在leveldb-db/skiplist.h文件中,有一个构造函数声明:

explicit SkipList(Comparator cmp, Arena* arena);

我知道带有单个参数的显式构造函数意味着构造函数参数没有隐式类型转换。但带显式关键字的双参数构造函数意味着什么?这是C++11的新规则吗?

谢谢。

使用C++11,您可以使用braked init lists来代替其他一些表达式,这会有所不同。例如,您可以在返回语句中使用它们:

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