c++ - Why must 'auto' declarations all be of the same type? -


it appears not allowed declare multiple variables of distinct types using auto keyword. can't figure out wording in standard prevent however.

auto = 1, j = 1.0; //deduction failure (several compilers) 

historically understand since have 1 decl-specifier-spec. however, rules in standard don't seem preclude, in fact encourage, auto can distinct type each. consider these paragraphs:

8-3 each init-declarator in declaration analyzed separately if in declaration itself.

7.1.6.4-7 if list of declarators contains more 1 declarator, type of each declared variable determined described above. [...]

even without auto not variables needed have same type, modifiers * applied each declarator individually. me appears wording allows each auto declarator distinct type.

which paragraph prohibit this?

type deduction performed every object in list, final result must single type [dcl.spec.auto]/7 (emphasis mine):

if list of declarators contains more 1 declarator, type of each declared variable determined described above. if type deduced template parameter u not same in each deduction, program ill-formed.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -