Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 114587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:53:04+00:00 2026-05-11T02:53:04+00:00

mmm, I have just a little confusion about multiple auto declarations in the upcoming

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T02:53:05+00:00Added an answer on May 11, 2026 at 2:53 am

    It’s probably not the latest, but my C++0x draft standard from June 2008 says you can do the following:

    auto x = 5; // OK: x has type int const auto *v = &x, u = 6; // OK: v has type const int*, u has type const int 

    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 v and u have the same ‘base type’ (int in this case) to use an inexact term.

    If you want the precise rule, The draft standard says this:

    If the list of declarators contains more than one declarator, the type of each declared variable is determined as described above. If the type deduced for the template parameter U is not the same in each deduction, the program is ill-formed.

    where the ‘deduced template parameter U’ is determined by:

    the deduced type of the parameter u in the call f(expr) of the following invented function template:

     `template <class U> void f(const U& u);` 

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

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

    is equivalent to:

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

    I don’t know. But I don’t write compilers. Probably something to do with once you’ve figured out the the auto keyword replaces, you can’t change it in the same statement.

    Take for example:

    int x = 5; CFoo * c = new CFoo();  auto  a1 = x,       b1 = c; // why should this be permitted if int   a2 = x, CFoo* b2 = c; // this is not? 

    In any case, I’m not a fan of putting multiple declarations on the same statement anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this textbox: <%= Html.TextBox(EffectiveDate, Model.EffectiveDate.HasValue ? Model.EffectiveDate.Value.ToString(dd-MMM-yyyy) : , new { @class
If I have a timestamp in the form: yyyy-mm-dd hh:mm:ss:mmm How can I just
I have the following Java: DateFormat formatter = new SimpleDateFormat( EEE MMM dd yyyy
I have a Date format: 2009-08-10T16:03:03Z that I want to convert to: @MMM dd,
Right now for my ConversionPattern I have: log4j.appender.A1.layout.ConversionPattern=%d{yyyy MMM dd HH:mm:ss,SSS} %5p [%t] (%F:%L)
I currently have a class called TextureObject. In the creation function I create the
I have dates in text format of the form dd-mmm-yy or d-mmm-y, where months
Please remember that I am not using any ORM tool. I have just written
Mmm it's difficult to explain it so I will do my best... I have
I have tried multiple date formats, but still I get nil back: Thu May

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.