Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class baza
  5. {
  6. protected:
  7. int x;
  8. public:
  9. baza(){};
  10. baza(int y) { x = y; };
  11. int getx() { return x; };
  12. ~baza(){};
  13. };
  14.  
  15. class pochodna : public baza //w tym miejscu używamy dziedziczenia, czyli dziedziczymy metody i konstruktory z klasy baza
  16. {
  17. int y;
  18. public:
  19. pochodna(){};
  20. pochodna(int n) { y = n; };
  21. pochodna(int n, int m) { y = n; x = m; };
  22. int gety() { return y; };
  23. ~pochodna(){};
  24. };
  25.  
  26.  
  27.  
  28. #include <iostream>
  29. #include "Header.h"
  30. using namespace std;
  31.  
  32.  
  33.  
  34. int main()
  35. {
  36. cout << "polimorfizm, dziedziczenie" << endl;
  37.  
  38. baza t(1223);
  39. pochodna c(1, 31);
  40. cout << c.gety() << endl;
  41. cout << t.getx() << endl;
  42. pochodna d(2, 3);
  43. cout << d.gety() << endl;
  44. pochodna f(33, 567);
  45. cout << f.gety() << endl;
  46.  
  47. baza *ptr;
  48. ptr = &c;
  49. //cout << ptr->getx() << endl;
  50. //ptr=&a;
  51. //cout << ptr->getx() << endl;
  52. /*a.getx();
  53. ptr = &a;
  54. ptr->getx();*/
  55. pochodna a(5, 4);
  56. baza b(5);
  57. baza *ptr;
  58. b = a;
  59. baza *ptr = &b; // nie da sie
  60. getchar();
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement