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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:25:32+00:00 2026-06-02T03:25:32+00:00

Let the source code speak for itself: MLine::MLine(int x1, int y1, int x2, int

  • 0

Let the source code speak for itself:

MLine::MLine(int x1, int y1, int x2, int y2)
{
}

MLine::MLine(double x1, double y1, double x2, double y2)
{
}

void __fastcall TVctDiag2::PrepareArrowTail(int x, int y)
{
    double length_x1;
    double length_y1;
    MLine *line = new MLine(x, y, x - length_x1, y - length_y1);
}

Compiler generates following error:

E2015 Ambiguity between ‘MLine::MLine(int,int,int,int) at shapes.h:100’ and ‘MLine::MLine(double,double,double,double) at shapes.h:110’

I can resolve this problem by following explicit casting:

    MLine *line = new MLine((double)x, (double)y, x - length_x1, y - length_y1);

The partial casting is not sufficient:

    MLine *line = new MLine((double)x, y, x - length_x1, y - length_y1);

I am quite confused about rules for implicit casting in expressions. Can someone explain this behaviour? What is the data type of expressions ‘x – length_x1’ and ‘y – length_y1’?

  • 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-06-02T03:25:34+00:00Added an answer on June 2, 2026 at 3:25 am

    I am quite confused about rules for implicit casting in expressions. Can someone explain this behaviour?

    The binary operators (+-*/ etc) work on operands of the same type (and return a result of the same type as their operands). If the types are not the same then one (usually but sometimes both) will be promoted so that both operands have the same type.

    What is the data type of expressions ‘x – length_x1’ and ‘y – length_y1’?

    X         => int
    length_x1 => double
    

    So the types are not the same. So one object will be promoted. In this case X will be promoted to a double (for why look up the promotion rules). The operator – will be applied and the result is a double.

    If we now look at your expression:

    MLine *line = new MLine(x, y, x - length_x1, y - length_y1);
    

    If I now replace the sub expressions with their types:

    MLine *line = new MLine(<int>, <int>, <double>, <double>);
    

    You can now see the dilemma of the compiler. There is no way for it to know which version of the constructor to choose (both can be reached by applying one round of casting). So it must generate an error.

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

Sidebar

Related Questions

Let's say you work someplace where every change to source code must be associated
Let's say I have created a program in C/C++ and have a source code.
FsUnit source code contains an unusual definition: let be = id FSI output: val
Let's say I want to rename a method in source code contained in a
Let's say I have the following within my source code, and I want to
Possible Duplicate: Dynamic source code in C++ is it possible to let the user
Within my Tcl script I'm building source code in another language. Let it be
i found sample plugin in android source code. let's say i can write a
Let's say I get the source code of some page (e.g. http://example.com ). I
Let me explain, this is about displaying class source code in IDEs. I have

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.