Deriving class help

This is a discussion on Deriving class help within the C++ Programming forums, part of the General Programming Boards category; I'm using various classes that derive off each other, and I'm coming across an error in my g++ compiler that ...

  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 01: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
    32,821
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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 03: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, 11: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, 03:39 PM
  4. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 02:09 PM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 02:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21