5

In his new book Effective Modern C++, Scott Meyers makes the statement in the section "Items 7: Distinguish between () and {} when creating objects," that:

I'll generally ignore the equals-sign-plus-braces syntax, because C++ usually treats it the same as the braces-only version.

Taking note of the "usually" qualifier, how does when and how does = { ... } differ from plain { ... }?

ThomasMcLeod
  • 7,603
  • 4
  • 42
  • 80
  • @Casey: This is a not duplicate. I was asking about the syntax forms `T{p}` and `T={p}`, which cover several types of initialization under the standard. The other question refers only to list initialization. My question is broader, for example it also covers C++ "value initialization" and C++ "aggregate initialization" as well as list initialization. – ThomasMcLeod Jan 28 '15 at 19:08
  • 1
    *List-initialization* is initialization of an object or reference from a *braced-init-list* ([dcl.init.list]/p1). It includes the aggregate initialization case for types that are aggregates, and the value initialization case of `{}` used with non-aggregates. – T.C. Jan 28 '15 at 19:12
  • @T.C., I'm not convinced. [dcl.inti.list] doesn't appear to cover agreegates. [dcl.init.aggr] covers aggregates. Also, [this page](http://en.cppreference.com/w/cpp/language/initialization) appears to me to distinguish between list initialization and aggregate initialization. – ThomasMcLeod Jan 28 '15 at 19:28
  • The master algorithm for initialization is in [dcl.init]/p17, which jumps to [dcl.init.list] in its first bullet for all *braced-init-list*s. In turn, the first bullet in [dcl.init.list]/p3 covers aggregates (by referring to [dcl.init.aggr]). – T.C. Jan 28 '15 at 19:51
  • @T.C., thanks for the references, I understand now. I did try searching before I posted this question. I searched for "brace initialization" and "curly brace initialization" but didn't find the referenced article. – ThomasMcLeod Feb 01 '15 at 06:12

0 Answers0