Advertisement
MeehoweCK

Untitled

Nov 27th, 2020
780
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Klasa
  6. {
  7.     int* wartosc;
  8. public:
  9.     Klasa(int);
  10.     Klasa(Klasa&);
  11.     ~Klasa() {if(wartosc) delete wartosc;}
  12.     void set_wartosc(int v) {*wartosc = v;}
  13.     int get_wartosc() {return *wartosc;}
  14.     int* pokaz_adres() {return wartosc;}
  15. };
  16.  
  17. Klasa::Klasa(int v)
  18. {
  19.     wartosc = new int;
  20.     *wartosc = v;
  21. }
  22.  
  23. Klasa::Klasa(Klasa& obiekt) : wartosc(new int)
  24. {
  25.     *wartosc = *(obiekt.wartosc);
  26. }
  27.  
  28. int main()
  29. {
  30.     Klasa A(10);
  31.     cout << A.get_wartosc() << endl;
  32.     Klasa B = A;
  33.     cout << B.get_wartosc() << endl;
  34.     A.set_wartosc(5);
  35.     cout << B.get_wartosc() << endl;
  36.     cout << A.pokaz_adres() << endl;
  37.     cout << B.pokaz_adres() << endl;
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement