我和我的好友最近一直在阅读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
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句