|
Virtual base classdan foydalanish
|
səhifə | 4/4 | tarix | 07.01.2024 | ölçüsü | 15,91 Kb. | | #210216 |
| 1) 13-mavzu(Polimorfizm)
- class base { public: int i; };
- class derived1 : virtual public base { public: int j; };
- class derived2 : virtual public base { public: int k; };
- class derived3 : public derived1, public derived2 {
- public: int sum;};
- derived3 ob;
- ob. i = 10;
- ob.j = 20;
- ob.k = 30;
- ob.sum = ob.i + ob.j + ob.k;
- void f(int i){cout<<"int";}
- void f(char c){cout<<"char";}
- int main() { f(10); return 0; }
- Natija: int
- class Base{ public: virtual void display(int i) { cout<<"Base::"<display(10); return 0;}
- Natija: Derv::10
- Herbert Shield “C++ The complete references – fourth edition” 2003. Part -2, Chapter – 17.
- TutorialsPoint – simply easy learning programming: http://www.tutorialspoint.com/cplusplus/cpp_inheritance.htm
- http://www.questionscompiled.com/answer/cpp/148/compile-time-polymorphism-and-run-time-polymorphism/
Xulosa -
- Polimorfizm bu – bitta nom bilan bir nechta funksiyalarni qayta yuklanishidir.
- C++ da polimorfizm 2 ta usulda namoyon bo’ladi:
- 1- usul: funksiyalar va operatorlarning qo’shimcha yuklanishida.
- 2- usul: vorislik va virtual funksiyalardan foydalanishda vujudga keladi.
- Mallayev Oybek
- Usmonqulovich
- E’TIBORINGIZ UCHUN RAHMAT!
Dostları ilə paylaş: |
|
|