Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "iostream"
- #include "vector"
- using namespace std;
- class A{
- public:
- int x; vector<int> y;
- A(){x=1; y.push_back(3);} A(int x){x = 10;}
- virtual void f(int a){x=5; cout << "afi" << endl; }
- virtual void f(double a){x=7; cout << "aff" << endl; }
- };
- class B:public A{
- public:
- int x; float y;
- B(){A(4); x=2; y=3;}
- void f(double y){x=2.5; y=2.5; cout << "bff"<< endl;}
- };
- class C:public A{
- public:
- int x; vector<int> y;
- C(){x=3;y.push_back(3);}
- void f(int m){x=4;y.push_back(A::x); cout << "cff" << endl; }
- };
- int main(){
- A* a = new A();
- B* b = new B();
- C* c = new C();
- cout << a->x << " " << b->x << " " << c->x << " " << (*b).A::x << " " << (*c).A::x << endl;
- a->f(3); b->f(3); c->f(3); b->f(3.7);
- cout << (*a).x << " " << (*b).x << " " << (*c).x << endl;
- vector<int>::iterator it; it = c->y.end() -1;
- cout << *it << " " << (*b).A::x << " " << (*c).A::x << endl;
- A* d = new C(); B* e = new B();
- cout << d->x << " " << d->A::x << " " << e->x << " " << e->A::x << endl;
- e->f(3); d = e;
- cout << e->x << " " << e->A::x << " " << d->x << endl;
- b->A::f(2.5); c->A::f(2.5);
- cout << b->x << " " << b->y << " " << b->A::x << " " << c->x << " " << c->A::x << endl;
- b->A::f(2); c->A::f(2);
- cout << b->x << " " << b->y << " " << b->A::x << " " << c->x << " " << c->A::x << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement