inheritance

I want to create a database.  I have 3 different levels of classes, each getting more specific.  Lets call the superclass "A".  A few different classes inherit from "A" as follows:
class a: public A{};
class b: public A{};
class c: public A{};
class d: public A{};

how can I inherit from the sub classes a,b,c,or d?

example
class thirdlevel: public a{};
class thirdlevel: public b{};
I have read a little about virtual classes but am not sure how to proceed.  Any help on this inheritance issue would be swell.
police45sAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sys_ProgCommented:
Virtual classes come into picture when a class might get include twice using inheriatnce
For example

class A {
    protected :
       int a ;
};
class B : public A {
    protected :
       int b ;
};
class C : public A {
    protected :
         int c ;
};
class D : public B, public C {
    protected :
         int d ;
} ;

In the above case,
Two instances of int a would be available in class D, thus leading to ambiguity

Thus, u inherit B and C from A virtually

class A {
    protected :
       int a ;
};
class B : virtual public A {
    protected :
       int b ;
};
class C : virtual public A {
    protected :
         int c ;
};
class D : public B, public C {
    protected :
         int d ;
} ;

Now, only one instanec of A gets into D


Amit

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
georg74Commented:
inheritance is just automatic copying of members, while retaining type compatibility.
so, in
    class B : public A {};
b will contain all members of A and be compatible with A.
each instance of B will in fact contain an instance of A.

Amit has given you example that shows the difference between
virtual and non-virtual base classes in C++.

to get basic help on inheritance in C++, I recommend to read
few relevant chapters from a C++ book or tutorial
and read relevant on-line help files that came with you rcompiler.
search for keywords class, virtual, public, private, protected, friend, ...

if you need a hint how to organize class structure for a distinct problem,
let us know a bit more.

gl,
georg
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.