c++ - Initialization by user-defined constructor -


consider following program:

#include <iostream>  struct {     a(int, int){ std::cout << "a(int, int)" << std::endl; } };  a(4,4); b{4,4}; c({4,4});  int main(){ } 

output:

a(int, int) a(int, int) a(int, int) 

demo

i' m intereste in there difference between initialization of a, b , c? of theme direct initialized.

a a(4,4); 

bog standard direct-initialization.

a b{4,4}; 

bog standard direct-list-initialization. since a has no initializer_list constructor, ends doing same thing above. no std::initializer_list object ever constructed or destroyed.

a c({4,4}); 

this direct-initializes c a temporary, in turn copy-list-initialized braced-init-list {4, 4}. note won't work if a::a(int, int) explicit, since in case copy-list-initialization ill-formed , left no viable constructor call. construction , destruction of temporary may elided, , is.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -