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 6079751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:58:58+00:00 2026-05-23T10:58:58+00:00

Below error related to auto , is understandable: auto i = int(), d =

  • 0

Below error related to auto, is understandable:

auto i = int(), d = double(); // error: inconsistent deduction for ‘auto’

However, why following is victimized with the same error:

struct B {};
struct D : B {};

const auto &b1 = B(), &b2 = D(); // error: inconsistent deduction for ‘auto’

Having known that, b1 is already deduced to const B&, can’t compiler try making b2 also a const B& ? (i.e. What kind of hazard it can cause if b2 would have been deduced to const B& ?)

  • 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. Editorial Team
    Editorial Team
    2026-05-23T10:58:58+00:00Added an answer on May 23, 2026 at 10:58 am

    The danger would be unexpected results… when you create a D, you expect to get a D as the result. There is also the fact that there is a cast involved… it is a “safe” cast, but a cast none-the-less. An identical argument could be made for the first example… why doesn’t the compiler just make d and int, since double can be converted trivially and it has already decided that is the type based on the result for i. Or what of the case where you have two sibling classes… should they both resolve to the common base?

    If you want that code to compile, you can always explicitly cast the result of D() so that both expressions yield the same type.

    And for the language lawyer bit:

    [decl.spec.auto]/7:

    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.

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

Sidebar

Related Questions

I am getting the below error when executing my application on a Windows XP
i'm getting the below error, When compiling the Asp.Net web deploy project Could not
I have a website that I get the below error on whenever I navigate
I'm going to guess that the answer is no based on the below error
I was changing the vc++ include directory with new paths suddenly getting below error
When I tried To Find Control n data List As I Mentioned Below Error(Object
This below codes give me error below: How to generate this codes help me
Anyone familiar with error below? When I run my webapp to generate a dynamic
I am getting the error below when I call my WCF service. What am
We are getting the error below calling c:\windows\syswow64\regsvr32.exe on Windows Server 2008 R2 x64.

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.