c++ - Coping with C++11 initialization syntaxes -


As a new uniform presents the initial syntax, many older styles use syntax instead of using it Recommend. At least, if it was not for the case of this so-called corner: {foo {foo {int} {std :: cout & lt; & Lt; "Default" & lt; & Lt; Std :: endl; } Fu (std :: initializer_list & lt; int & gt;) {std :: cout & lt; & Lt; "Initist" & lt; & Lt; Std :: endl; }}; Int main () {F.F. F. {200}; // print "initlist"}

Using a {} -ways-style screams for trouble, especially for the new syntax in the template only takes three safe uses: < / P>

  1. Clearly request for std :: initializer_list-constructors
  2. POD-constructors
  3. default-constructor

    But there is also a case in which we have to use the same initial syntax: Non-static data member initiator can identify C ++ for some reason

      zero times () {foo f (200); }   

    but

      straight bar {FUF (200); };   

    Question # 1: Why inside the function () -Syntex works, but no classes? Does anyone know the logic behind this?

    By putting it together, at the end we reach this silly case:

    Of course, you can not even use auto for data members. So I have to combine all the syntaxs oddly or do not use these facilities at all.

    Question # 2: Was not I wrong? Its behavior can not be treated, is it

    Question # 1: Why does () -Syntex works inside the function, but no class? Does anyone know the logic behind this?

    Because it can look like a function declaration, and it already has enough confusion:

      Foo f (); // function declaration still excludes people   

    but you can use () , just Copy-initialization syntax:

      tt = t (args); Question # 2: Did I do something wrong? This behavior can not be intended, maybe?   

    This is a design behavior, it is unfortunate that this standard type of standard library containers (such as std :: vector & lt; int & gt; in your example) Does not play very well with. All you have to do is remember that a vested initializer_list constructor harasses all other relevant constructors.

    Look at this related question: You can try to design your own orbits that they are not suffering from this problem.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -