c++11 - How the C++0x standard defines C++ Auto multiple declarations? -


mmm, I have some confusion about several auto announcements in the upcoming C + 0x standard.

  auto a = 10, b = 3.f, * c = new square ();  

Somewhere I have read that this permission is not the reason (?) Because it was not clear that continuous declarations should have the same type of earlier (for example, en) or not. Possible translation 1:

  int a = 10; Int b = 3.f; Int * c = new square ();   

Float B = 3.F; Class * c = new square ();

How does this result in the standard?

If I can say my POV, the translation # 2 was the most obiouvs, at least for me that I mean a regular C ++ user I mean, declare me "declare every declaration" , Witch Auto's translation # 1 will really be intuitive for me.

Goodbye by QbProg

Maybe this is not the latest, but since June 2008 my The C + 0x draft standard can tell you:

  auto x = 5; // OK: Type int in Auto * V = & amp; X, U = 6; // OK: v is type const int *, type of type const int  

So unless something has changed since June it is a very intuitive in a limited form (Or will be) interpreted.

The limit is that if you want to string several auto announcements like this (using the example given above), this works because this estimate code is v And

If you want the exact rule, then the draft standard says:

If there is more than one declarator in the list of declarations, then each declaration The variable type is determined according to the above if the template Parameters used type U is not the same in each cut, the program causes the illness.

Where "Estimated Template parameter is defined by the U":

The following invention is the type of parameter U in the call template (XPR) :

  `template & lt; Square u & gt;   

Why have they come up with this rule instead of saying something like this:

  Auto A = 10, B = 3.f, * c = new square ();  

equals:

  auto a = 10; Auto B = 3. F; Auto * c = new square ();  

I do not know but I do not write compiler It is possible that once you find out the keyword auto , you can not change it in that statement .

Take for example:

  int x = 5; CFoo * c = New CFoo (); Auto a1 = x, b1 = c; // Why it should be allowed if int a2 = x, CFoo * b2 = c; // is not it?  

In any case, I'm not a fan of putting several announcements on the same statement anyway.


Comments