M
M
mlwrm2016-04-04 23:51:31
C++ / C#
mlwrm, 2016-04-04 23:51:31

How to solve the problem with multiple inheritance?

There is a base class First containing 1 absolutely virtual function


virtual QString getInfo() =0;

2 Derived classes Basic, Vip, and
class Basic : virtual public First
class Vip : public Basic, public OtherClass (completely different class, does not belong to this hierarchy)

And there is the SuperVip class, which is the cause of the problem.
class SuperVip : public Vip, public Basic

when i try to do the following
SuperVip* svip = dynamic_cast<SuperVip*>(tmpBasic)  //некий указатель на Basic
QString result = svip->Basic::getInfo();

I receive
Basic is an ambiguous base of SuperVip

Pointing to the string with result
I understand that this is due to the fact that SuperVip inherits Basic and Vip, in turn, also inherits Basic, so the uncertainty is obtained.
I need to solve it without using virtual inheritance, please tell me how to explicitly tell the compiler which method to use and avoid uncertainty?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question