Thread: Deriving class help

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    16
    I'm using various classes that derive off each other, and I'm coming across an error in my g++ compiler that says "‘A’ is an ambiguous base of ‘D’". My code goes something like this:

    class A {...};
    class B : public A {...};
    class C : public A {...};
    class D : public B, public C {...};

    I assume this error is because I am referencing class A twice, indirectly, but my instructions are to derive a class D from both classes B and C. I appericate any and all help!

    My main function goes something like

    int main()
    {
    vector<A*>v;
    v.push_back(new D(...));
    cout<<...;
    }
    Last edited by bigboybz; 03-17-2011 at 12:13 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    It seems to me that you've got one of these
    Diamond problem - Wikipedia, the free encyclopedia
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    16
    so class B : virtual public A?
    Thanks

    I also get this error: "conversion from ‘A*’ to non-scalar type 'A' requested"
    Last edited by bigboybz; 03-17-2011 at 02:03 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about design class..
    By ovid in forum C++ Programming
    Replies: 5
    Last Post: 03-17-2010, 10:34 AM
  2. Whats the best way to control a global class?
    By parad0x13 in forum C++ Programming
    Replies: 3
    Last Post: 11-12-2009, 05:17 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 01:09 PM