Help me sort out the meaning of "{}" as a constructor argument--Scott Meyers

Discussion on "Distinguish between () and {} when creating objects".

Help me sort out the meaning of "{}" as a constructor argument

by Scott Meyers 

From the article:

My experiments showed that one factor affecting whether "{{}}" as an argument list yields a zero-length std::initializer_list<T> was whether T had a default constructor, so I threw together some test code involving three classes, two of which could not be default-constructed. I then used both "({})" (note the outer parentheses) and "{{}}" as argument lists to a constructor taking a std::initializer_list for a template class imaginatively named X. When the constructor runs, it displays the number of elements in its std::initializer_list parameter.

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.