我和我的朋友最近一直在阅读leveldb源代码。我们遇到了这个问题。在leveldb db/skiplist.h文件中,有一个构造函数声明:
explicit SkipList(Comparator cmp, Arena* arena);
我知道只有一个参数的显式构造函数意味着构造函数参数没有隐式类型转换。但是带有显式关键字的双参数构造函数是什么意思呢?这是C++11的新规则吗?
谢谢。
发布于 2013-07-15 15:01:54
在C++11中,您可以使用带括号的初始化列表来代替其他一些表达式,这会有所不同。例如,您可以在return语句中使用它们:
SkipList foo() {
return {{}, nullptr}; //does not compile with explicit constructor
return SkipList{{}, nullptr}; //compiles with or without explicit constructor
}
https://stackoverflow.com/questions/17648239
复制相似问题