P
P
Pavel K2016-11-12 01:54:23
C++ / C#
Pavel K, 2016-11-12 01:54:23

Inheritance and how to correctly cast interface types?

Greetings!
Please help me understand how to do it better:
and so, there is class A and its interface IA, which is inherited from class B with interface IB

class A: public IA, public B
{
public:
 void a();
}

class IA 
{
public:
 virtual a()=0;
}

class B: public IB
{
public:
 void b();
}

class IB 
{
public:
 virtual b()=0;
}

At some point in the program, I get a pointer to IA*,
but I need to call methods from B,
but the interface IA is not inherited from IB (if it were inherited, there would be a "... is ambiguous" error),
and only IA or IB can be used without the ability to access A or B.
So, how can I most correctly create these two classes and their interfaces (A, IA, B, IB), so that I could do this:
IA * a = ....;
a->b(); ???

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel K, 2016-11-12
@PavelK

Ya dude. The decision that the elementary - virtual inheritance!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question