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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:08:22+00:00 2026-06-08T13:08:22+00:00

Will this cause an ambiguity?: class A { … }; class B : public

  • 0

Will this cause an ambiguity?:

class A { ... };
class B : public A {
//...
B(const B& b);
B(const A& a);
//...
};
  • 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-08T13:08:23+00:00Added an answer on June 8, 2026 at 1:08 pm

    Update: It appears that the asker has scrubbed the class names from the question. Here is the original piece of code for which this answer is written:

    class Vector2D { ... };
    class Vector3D : public Vector2D {
    //...
    Vector3D(const Vector2D& b);
    Vector3D(const Vector3D& a);
    //...
    };
    

    I said “no” earlier, but I changed my mind. This is ambiguous, and I can’t think of a good reason to have Vector3D inherit from Vector2D.

    From a mathematical perspective, a 2D vector space can be extended to a 3D vector space, but there are many extensions to choose from — they are not unique. So when you make a 3D vector class that inherits from a 2D vector class, you are making one embedding of the 2D space in the 3D space “privileged” and all other embeddings inferior. I don’t think that’s particularly useful.

    The other thing that you are doing is you are saying that “every 3D vector is a 2D vector”, which is just kind of silly. For example, maybe you write a function:

    // Compute the angle between two vectors
    double angle(Vector2D x, Vector2D y);
    

    Let’s suppose that you forgot to write the version for 3D vectors. Now, the compiler won’t be able to give you an error message: instead, your 3D vectors will get projected into 2D space using the “privileged” projection you chose when creating the class, and you will get the wrong answer. Now suppose you add another function:

    // Compute the angle between two 3D vectors
    double angle(Vector3D x, Vector3D y);
    

    Now, there’s still a problem.

    Vector3D x = ...;
    Vector2D y = ...;
    double a = angle(x, y);
    

    This will use the 2D projection of x, and again, you won’t get a compiler warning. You’ll just get the wrong answer.

    Summary: This is the worst kind of ambiguity: it is the kind of ambiguity where the compiler will give you the answer that you don’t expect.

    Vector3D should not inherit from Vector2D. It is mathematically illogical.

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

Sidebar

Related Questions

Can I use free for const char* ? Will this cause any problems?
Can anyone please suggest me whether this code will cause concurrency or not. This
Can anyone tell by looking at this style will cause a combobox with it
Under what circumstances will _declspec( novtable ) cause an access violation? For example, this
I have this code: <script id=toModify > Invalid javascript that will cause errors </script>
Will this cause any harm? Does it serve any purpose other than tell browsers
I want to remove the first line: !string.IsNullOrEmpty(cell.Text) will this cause any issue? I
I know free() won't call the destructor, but what else will this cause besides
What will you do in this case to reduce the Cyclomatic Complexty if (Name.Text
This case is a bit complex, I hope I will simplify it well. My

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.