Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
please any one can explain to me how to add an interface to multiple inheritance such as we have class c inherited from class A and class B.
THANK YOU IN ADVANCE
Posted
Comments
[no name] 18-Nov-15 20:42pm    
Question is not clear. Are class A and B interfaces? http://www.linuxtopia.org/online_books/programming_books/c++_practical_programming/c++_practical_programming_220.html
Member 12151065 18-Nov-15 21:35pm    
thank you for you replay I want to add an interface to multiple inheritance ,l just need it by example ,class a and class b they are not interface i want to add interface for them
[no name] 18-Nov-15 21:49pm    
Still not clear. What did you learn from the link? Edit your question to provide more information.
Member 12151065 18-Nov-15 22:16pm    
dear pwasser firstly I want to thank you for this link , and acually I have a multiple inheritance UML MOdel for c++ language ,I Can explain it by giving some clarification about it:if I have class A contain attribute a,methods get_(),disp_a(),boject nill. class B contain attributes b,c,s ,methods get_b,get_c ,sum_bc(). class c inherited from both of them CLASS C contain attributes d e S1, Methods get_d() ,get_e() ,disp_e() , sum abcd, disp_a() , sum_bc() ,object c1. – please I really need it for starting my assignment,thank you for your help.
Philippe Mori 18-Nov-15 21:51pm    
1) What do you have so far?
2) What is the problem with adding interfaces? Show an example and tell use where you want to add something. Assuming that you want to add IA and IB as parent of A and B, it is trivial so I don't know what you want.
3) You should avoid multiple inheritance and even more if you don't understand it. It is far too easy to misuse and make system hard to maintains (say you have A1, A2 and A3 and also B1 and B2, then you want most combinations... you end up with a lot of class).

1 solution

If I understand you correctly you already have a class that inherits from two other classes and now you want to add an interface to the pot.
Is that about right?

In any case to use interfaces in C++ you need to use COM and IDL files and you probably don't want to go down that path.

Instead, in C++ you use abstract classes and you can read about and find examples here
Interfaces in C++ (Abstract Classes)[^]
 
Share this answer
 
v2
Comments
Member 12151065 18-Nov-15 22:26pm    
exactly that is what I want,please could you help me for write c++ code from this example:I have class A contain attribute a,methods get_(),disp_a(),boject nill. class B contain attributes b,c,s ,methods get_b,get_c ,sum_bc(). class c inherited from both of them CLASS C contain attributes d e S1, Methods get_d() ,get_e() ,disp_e() , sum abcd, disp_a() , sum_bc() ,object c1.
George Jonsson 18-Nov-15 22:31pm    
I think you will find all the help you need if you search a little bit in different C++ tutorials.
You seem to know what you want to do, so it is just a matter to find a way to do it.
See also this link http://www.cprogramming.com/tutorial/multiple_inheritance.html[^]

You don't pay me enough to make it worth writing your code. :-)
Member 12151065 18-Nov-15 22:39pm    
thank you so much for you help dear
George Jonsson 18-Nov-15 22:43pm    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900