|
Guruh talabasi Omonbayev Jaloliddin Mavzu
|
tarix | 03.01.2023 | ölçüsü | 27,58 Kb. | | #121958 |
| 18. Qayta yuklash va qayta aniqlash usullari. Do’stona va virtual funksiyalar ustida amallar
911-21 guruh talabasi Omonbayev Jaloliddin
Mavzu: Qayta yuklash va qayta aniqlash usullari. Do’stona va virtual funksiyalar ustida amallar
1.
#include
using namespace std;
class base {
public:
virtual void print(){
cout << "asosiy sinfni chop etish\n"; }
void show(){
cout << "asosiy sinfni ko'rsatish\n"; } };
class derived : public base {
public:
void print(){
cout << "print derived class\n";}
void show(){
cout << "olingan sinfni ko'rsatish\n"; } };
int main(){
base *bptr;
derived d;
bptr = &d;
bptr->print();
bptr->show();
return 0;}
2.
#include
using namespace std;
class base {
public:
void fun_1() { cout << "asos-1\n"; }
virtual void fun_2() { cout << "asos-2\n"; }
virtual void fun_3() { cout << "asos-3\n"; }
virtual void fun_4() { cout << "asos-4\n"; }
};
class derived : public base {
public:
void fun_1() { cout << "olingan-1\n"; }
void fun_2() { cout << "olingan-2\n"; }
void fun_4(int x) { cout << "olingan-4\n"; }
};
int main(){
base *p;
derived obj1;
p = &obj1;
p->fun_1();
p->fun_2();
p->fun_3();
p->fun_4();
return 0;}
Dostları ilə paylaş: |
|
|