|
Virtual base classdan foydalanish
|
səhifə | 4/4 | tarix | 07.01.2024 | ölçüsü | 15,91 Kb. | | #210216 |
| 1) 13-mavzu(Polimorfizm)
Virtual base classdan foydalanish - 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;
- Bu holatda dastur to’g’ri ishlaydi
Funksiya overloadi uchun misol - void f(int i){cout<<"int";}
- void f(char c){cout<<"char";}
- int main() { f(10); return 0; }
- Natija: int
Funksiya override uchun misol - class Base{ public: virtual void display(int i) { cout<<"Base::"<display(10); return 0;}
- Natija: Derv::10
- Agar “virtual” kalit so’zi olib tashlansa
- Natija: Base::10
Foydalanilgan adabiyotlar - 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.
- MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
- Mallayev Oybek
- Usmonqulovich
- “Informatika asoslari” kafedrasi dotsenti
- E’TIBORINGIZ UCHUN RAHMAT!
Dostları ilə paylaş: |
|
|