mmm, I have just a little confusion about multiple auto declarations in the upcoming C++0x standard.
auto a = 10, b = 3.f , * c = new Class();
somewhere I read it is not allowed. The reason was(?) because it was not clear if the consecutive declarations should have the same type of the first one , (int in the example) , or not.
Possible translation 1:
int a = 10; int b = 3.f; int * c = new Class ();
causing an error
Possible translation 2:
int a = 10; float b = 3.f; Class * c = new Class ();
how it is resulted in the standard?
If I can say my POV, translation #2 was the most obiouvs, at least for me that I’m a regular C++ user . I mean, for me ‘every variable declared is of the same declared type’, witch is auto. Translation #1 would be really un-intuitive to me.
Good Bye QbProg
It’s probably not the latest, but my C++0x draft standard from June 2008 says you can do the following:
So unless something has changed from June this is (or will be) permitted in a limited form with a pretty intuitive interpretation.
The limitation is that if you do want to string multiple auto declarations like this (using the example above), it works because the inferred type of
vanduhave the same ‘base type’ (int in this case) to use an inexact term.If you want the precise rule, The draft standard says this:
where the ‘deduced template parameter U’ is determined by:
Why they’ve come up with this rule instead of saying something like:
is equivalent to:
I don’t know. But I don’t write compilers. Probably something to do with once you’ve figured out the the
autokeyword replaces, you can’t change it in the same statement.Take for example:
In any case, I’m not a fan of putting multiple declarations on the same statement anyway.