16

My buddy and I have been recently reading leveldb source code. And we encounter this problem. In leveldb db/skiplist.h file, there is a constructor declaration:

explicit SkipList(Comparator cmp, Arena* arena);

I know explicit constructor with single parameter means no implicit type conversion for constructor parameter. But what does double parameters constructor with explicit keyword mean? Is it new rule of C++11?

Thanks.

lulyon
  • 6,707
  • 7
  • 32
  • 49

1 Answers1

16

With C++11, you can use braced-init-lists in place of some other expressions, and that makes a difference. For instance, you can use them in return statements:

SkipList foo() {
    return {{}, nullptr}; //does not compile with explicit constructor
    return SkipList{{}, nullptr}; //compiles with or without explicit constructor
}
chris
  • 60,560
  • 13
  • 143
  • 205
  • By uniform initialization You mean initializing multiple parameter like initializing an array? – lulyon Jul 15 '13 at 07:12
  • 1
    @lulyon, Uniform initialization generally results from using braces. You can use them to call constructors, as shorthand for `TypeName()`, and to eliminate the most vexing parse. It's actually quite a significant feature of C++11. You should look up some information on it. – chris Jul 15 '13 at 07:16
  • This is called *list initialization* – M.M Apr 11 '16 at 09:33
  • @M.M, Thanks, I changed it to use *braced-init-list* instead to match the "top level" of wording, even though it is list-initialized when all is said and done. – chris Apr 11 '16 at 19:31
  • I wouldn't be surprised if this constructor originally had a default argument (or was adapted from a single-argument constructor). There's not that many cases where you'd actually want to disable copy-list-initialization. – T.C. Apr 11 '16 at 19:33
  • @T.C., True, I guess these aren't all that common in the wild. – chris Apr 11 '16 at 21:52