Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include "iostream"
  2. #include "vector"
  3. using namespace std;
  4. class A{
  5. public:
  6. int x; vector<int> y;
  7. A(){x=1; y.push_back(3);} A(int x){x = 10;}
  8. virtual void f(int a){x=5; cout << "afi" << endl; }
  9. virtual void f(double a){x=7; cout << "aff" << endl; }
  10. };
  11. class B:public A{
  12. public:
  13. int x; float y;
  14. B(){A(4); x=2; y=3;}
  15. void f(double y){x=2.5; y=2.5; cout << "bff"<< endl;}
  16. };
  17. class C:public A{
  18. public:
  19. int x; vector<int> y;
  20. C(){x=3;y.push_back(3);}
  21. void f(int m){x=4;y.push_back(A::x); cout << "cff" << endl;  }
  22. };
  23.  
  24. int main(){
  25. A* a = new A();
  26. B* b = new B();
  27. C* c = new C();
  28. cout << a->x << " " << b->x << " " << c->x << " " << (*b).A::x << " " << (*c).A::x << endl;
  29. a->f(3); b->f(3); c->f(3); b->f(3.7);
  30. cout << (*a).x << " " << (*b).x << " " << (*c).x << endl;
  31. vector<int>::iterator it; it = c->y.end() -1;
  32. cout << *it  << " " << (*b).A::x << " " << (*c).A::x << endl;
  33. A* d = new C(); B* e = new B();
  34. cout << d->x << " " << d->A::x << " " << e->x << " " << e->A::x << endl;
  35. e->f(3); d = e;  
  36. cout << e->x << " " << e->A::x << " " << d->x << endl;
  37. b->A::f(2.5); c->A::f(2.5);
  38. cout << b->x << " " << b->y << " " << b->A::x << " " << c->x << " " << c->A::x << endl;
  39. b->A::f(2); c->A::f(2);
  40. cout << b->x << " " << b->y << " " << b->A::x << " " << c->x << " " << c->A::x << endl;
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement