I don't know how many C++ coders might be out there, but I've been trying to get this question answered about multiple inheritance.

Say I have a class called B that inherits from A:

A -> B

Now, I create a class called C that, perhaps due to programmer unfamiliarity with the library, multiply-inherits from both A and B like this:

A -> B -> C <- A

Is C++ going to barf on that, or does it handle things more intelligently? Thank you!

Recommended Answers

All 5 Replies

>Is C++ going to barf on that
Possibly. It depends on whether A contains data members and if having multiple copies of the A subobject within a C object would cause problems in your code. Virtual inheritance was introduced to alleviate these kinds of problems.

Thanks, Narue. Given that I'm trying to work out a framework for audio DSP, I'd have to say that any chance of messing up via inheritance must be avoided.

It's say the chance of messing up due to inheritance is the least of your problems. Attempting to avoid problems due to X without even a basic understanding of how X works is a recipe for disaster.

And trying to design a framework on that basis is asking for trouble. Framework designers normally need experience in the domain (in your case DSP) in order to understand the benefits and pitfalls the framework seeks to address, design experience, and experience in programming language(s) that might be be used to implement it. As a starting point.

I'm fairly well-versed in the maths of DSP. It's the programming part I'm not so good at. A fellow I know in IRC, who is a CS whiz, is helping me out with the framework design, and it sounds like it'll work beautifully. Thanks for the help, all!

In that case, I suggest you let the "CS whiz" worry about the design and implementation of the framework. Stick to what you know: the end user (you) is critically important for defining requirements, but the end-user lacking knowledge of design and implementation is better off avoiding the temptation to make specialised design and implementation decisions (such as if/how to use inheritance).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.