Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. struct VerboseObject{
  7.     string nazwa;
  8.  
  9.     VerboseObject(string nazwa){
  10.         this->nazwa = nazwa;
  11.         cout << "JA: " << nazwa << " zostalem utworzony!" <<endl;
  12.     }
  13.  
  14.  
  15.     ~VerboseObject(){    //~ TYLDA
  16.         cout << "JA: " << nazwa << " zostalem ZNISZCZONY!" <<endl;
  17.     }
  18.  
  19.     void saySomething(){
  20.         cout << "NA MNIE: " << nazwa << " zostala wywolana metoda!" <<endl;
  21.     }
  22.  
  23. };
  24.  
  25.  
  26. int main()
  27. {
  28.     // JAK TWORZYC OBIEKTY:
  29.  
  30.     VerboseObject *o3 = new VerboseObject("Object3");
  31.     static VerboseObject o2("Object2"); //statyczna zmienna niszczona zawsze na koncu
  32.     VerboseObject o1("Object1");    //1 SPOSOB
  33.  
  34.     o2.saySomething();
  35.     o1.saySomething();
  36.     o3->saySomething();
  37.  
  38.     delete o3;                           //o3->~VerboseObject();
  39.  
  40.  
  41.  
  42.     return 0;
  43.     //usuwanie o2 oraz o1
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement