0

While reading Cpp Primer 5ed Chapter15.8.1 (page631), I am confused by the definition of private member - item.

The original goes like:

std::multiset<std::shared_ptr<Quote>, decltype(compare)*> items{compare};

Shouldn't this be like:

std::multiset<std::shared_ptr<Quote>, decltype(compare)*> items(compare);

Here the compare works as the constructor argument.

1 Answers1

1

Either works.

Since C++11, it's valid to specify an initializer, including cases that call a constructor, using {}.

One difference is that the form using {} causes overload resolution to prefer initializer_list constructors, but as long as compare can't possibly convert to std::shared_ptr<Quote>, that's not an issue here.

aschepler
  • 70,891
  • 9
  • 107
  • 161