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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:23:17+00:00 2026-05-24T09:23:17+00:00

I have some troubles with the application of polymorphism in this example. This question

  • 0

I have some troubles with the application of polymorphism in this example. This question is similar to my last question

C++, virtual inheritance, strange abstract class + clone problem

There are 3 abstract classes:

class A
{
public:
    virtual A  * copy () const = 0;
    virtual ~A() = 0;
};

A::~A(){}

class B
{
public:
    virtual B  * copy () const = 0;
    virtual ~B() = 0;
};

B::~B(){}

class C: virtual public A , public B 
{
public:
    virtual C  * copy () const = 0;
    virtual ~C() = 0;
};

C::~C(){}

and two inherited classes using the virtual inheritance

class D: virtual public A
{
public:
    virtual D  * copy () const {return new D  (*this);}
    virtual ~D() {}
};

class E: virtual public D , public C
{
public:
    virtual E * copy () const {return new E (*this);}
    virtual ~E() {}
}; //Error C2250: 'E' : ambiguous inheritance of 'D *A::copy(void) const

The above mentioned error occurs only using MSVS 2010 compiler, g++ compiles this code OK.

Class diagram (simplified)

.......... A .... B.....
........../.\..../......
........./...\../.......
......../.....\/........
.......D...... C........
........\...../.........
.........\.../..........
..........\./...........
...........E............

Last discussion we close with the result: remove the declaration of the copy() method from class C.

class C: virtual public A , public B 
{
public:
    //virtual C  * copy () const = 0; //remove declaration
    virtual ~C() = 0;
};

C::~C(){}

My sample code using polymorphism needs to create vector of pointers to C. After removing some element I want to create its copy… I NEED a declaration of copy() in class C, so removal of the declaration is insufficient and it does not solve the problem.

int main(int argc, char* argv[])
{
std::vector <C*> items;
items.push_back(new E());
items.push_back(new E());
items[0]->copy();
return 0;
}

Could you help me, please how to correct the code to be translatable using VS 2010?

  • 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-24T09:23:18+00:00Added an answer on May 24, 2026 at 9:23 am

    This is a known bug in Visual C++:

    Visual C++ incorrectly reports ambiguity when covariance is used with virtual inheritance

    You either need to eliminate the covariance or the virtual inheritance. Unfortunately, you can’t have both.

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

Sidebar

Related Questions

I have some troubles with positioning my label/password field. With this code they both
I'm having some troubles with binding data. I have an application that contains a
Especially android-developers :) I have some troubles with application menu which i try to
Greetings! I have some troubles enabling OAuth authentication for my web application running on
Have a lot of troubles on production server. Some routing cause crashing of Application
I have some trouble with jquery ui-events: In my application, there are some sliders.
I have some trouble achieving adequate real-time performance from my application and wondering if
I have just installed Delphi 2010 and got some troubles with idHTTP component. If
I have some troubles installing air files that've been built with air2.0beta or air2.0beta2
Happy Friday SO! I'm building a multi-WinForm application and am having some troubles. I

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.