Sample code of these oop words. Any replies would be appreciated. Thank's
1.Single inheritance
2.Multiple inheritance
3.Multi-level inheritance
4.Ad hoc polymorphism
5.Pure Polymorphism
This is a discussion on Inheritance and Polymorphism within the C++ Programming forums, part of the General Programming Boards category; Sample code of these oop words. Any replies would be appreciated. Thank's 1.Single inheritance 2.Multiple inheritance 3.Multi-level inheritance 4.Ad hoc ...
Sample code of these oop words. Any replies would be appreciated. Thank's
1.Single inheritance
2.Multiple inheritance
3.Multi-level inheritance
4.Ad hoc polymorphism
5.Pure Polymorphism
Last edited by bench386; 03-19-2004 at 12:01 AM.
1) A->B
A B (2
\ /
C
3) A->B->C
4) & 5) difference between ad hoc and pure in this context, haven't the foggiest. Sorry.
1.Single inheritance
-- example:
2.Multiple inheritanceCode:class myClass1 { // stuff }; class myClass2:public myClass1 { // more stuff, but now can use stuff from myClass1 too };
-- example:
3.Multi-level inheritanceCode:class myClass1 { // stuff }; class myClass3 { // stuff2 }; class myClass2:public myClass1, public myClass3 { // more stuff, but now can use stuff from myClass1 and myClass3 too };
-- example:
4.Ad hoc polymorphismCode:class myClass1 { // stuff }; class myClass3:public myClass1 { // can use stuff from myClass1 }; class myClass2:public myClass3 { // more stuff, but now can use stuff from myClass1 and myClass3 too };
5.Pure Polymorphism
polymorphism has to do with stuff like this:
-- example:
We create a myClass1 pointer, but instantiate it with a myClass2 type, This is really nice because we could swap in and out different "modules" just by changing one pointer!Code:class myClass1 { virtual void myFunc()=0; // Means it must be implemented by the inheriting class }; class myClass2:public myClass1 { void myFunc(); }; myClass1* shell=new myClass2(); shell->myFunc(); // Calls myFunc from myClass2