Using virtual inheritance to solve multiple inheritance issues

Hi there,
I have to use virtual inheritance to resolve ambiguous function compiler errors.  Although, it works now I wanted to make sure there are no disadvantages in using virtual inheritance.
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.

This is hard to answer without seeing your code. An educated guess would be '42' ;o)
actually by adding functions (what normally is the case if using virtual functions)  you increase the probability of adding ambiguous functions.

so the general recipe for solving ambiguity is to reduce functions such to avoid ambiguity in the first case. you never would get such errors if there is only one function with the specific name. next thing is to avoid an ambiguous interface if arguments easily could casted by the compiler.  for example if you have two functions which only differ that one has a const char * as input argument while another has a const string or const string &, the first one easily can removed since the compiler easily could find the second one regardless if you provide a literal string or a string variable.

so before you change inheritance model you definitively should try to have a well-defined interface which avoids ambiguous functions.

Since you have chosen to design your program using multiple inheritance and to take good advantage of dynamic polymorphism, then to avoid ambiguous functions  (and possibly as well as the dreaded diamond, if applicable), then you must use virtual inheritance. For your design, then, you have no choice, so pros/cons of using virtual inheritance becomes a moot point.

Maybe the real question is whether there is a disadvantage in using Multiple Inheritance. Naturally, as with any inheritance, the instances are larger and the dynamic calling of derived instance methods takes a little longer.

I believe that in some cases, MI can lead to more difficult maintenance of legacy code due to the additional coupling. But those are design issues. Here is a discussion that may provide you with further assistance.

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
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

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.