1

I know explicit constructor is not allowed for copy-list-initialization, but OK for direct-list-initialization. Besides this, is there any other difference?

goodbyeera
  • 3,169
  • 2
  • 18
  • 39
  • http://www.cprogramming.com/tutorial/initialization-lists-c++.html this may be useful – Chethan N Feb 18 '14 at 10:56
  • @CouchDeveloper: Thanks for pointing out the possible duplication. Just to confirm if I interpret the answer of that question appropriately, the answer to my question here is no, correct? – goodbyeera Feb 18 '14 at 11:11
  • You may read **§13.3.1.3 Initialization by constructor**, and also §13.3.1.ff. It should help to explain the answer. – CouchDeveloper Feb 18 '14 at 11:49
  • @CouchDeveloper: Thanks for referencing the relevant part from the standard, but I don't have much idea about what that paragraph is saying. It will be so kind of you if you could give a code sample that demonstrates the difference between `T a {...};` and `T a = {...};` (with the same contents in `...`). What kind of `T` and `{...}` will make those two forms of initialization different as specified by §13.3.1.3 or any other rules, except for the case of explicit constructor? – goodbyeera Feb 18 '14 at 12:02
  • The relevant topic for _list-initialization_ is **§13.3.1.7**. There are subtle differences, when you compare §13.3.1.3 and §13.3.1.7. Additionally, the there are subtle differences in copy-list-initialization and direct-list-initialization: _"In copy-list-initialization, if an *explicit* constructor is chosen, the initialization is ill-formed."_ Now, then the question arises what happens actually when a an ill-formed function (explicit constructor) becomes a _viable_ function. – CouchDeveloper Feb 18 '14 at 12:25
  • @CouchDeveloper: I'm even more confused. The copy-list-initialization is ill-formed if an explicit constructor is chosen. What happens then? – goodbyeera Feb 18 '14 at 12:50
  • @goodbyeera I'm actually not sure what the standard dictates in this case, but **clang** will issue an error "Chosen constructor is explicit in copy-initialization" if an explicit constructor would be the best match, and others would fail for example due to narrowing. – CouchDeveloper Feb 19 '14 at 10:04
  • clang will also issue an error "Chosen constructor is explicit in copy-initialization" if the explicit constructor would be the best match, and others would be viable but would require a conversion. – CouchDeveloper Feb 19 '14 at 10:17

0 Answers0