Guest User

Untitled

a guest
Nov 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. class Dupa {
  4. public:
  5. int *i;
  6. std::string string;
  7. Dupa(std::string string) {
  8. std::cout << "konstruktor " << string << std::endl;
  9. this->string = string;
  10. i = new int(5);
  11. }
  12.  
  13. Dupa(Dupa &other) {
  14. std::cout << "kopiujący" << std::endl;
  15. i = new int(*other.i);
  16. this->string = other.string + "_copy";
  17. }
  18.  
  19. void operator=(Dupa other) {
  20. std::cout << "oeprator =" << std::endl;
  21. i = new int(*other.i);
  22. string = other.string + "_=";
  23. }
  24.  
  25. Dupa operator+(Dupa other) {
  26. std::cout << "++++" << std::endl;
  27. Dupa dupa("dupa_op_+");
  28. *dupa.i = *i + *other.i;
  29. dupa.string = string + other.string;
  30. return dupa;
  31. }
  32.  
  33. ~Dupa() {
  34. std::cout << "delete" << std::endl;
  35. delete i;
  36. }
  37.  
  38. void print() {
  39. std::cout << "print: " << *i << std::endl;
  40. }
  41.  
  42.  
  43. };
  44.  
  45. int main() {
  46. Dupa p1("pierwej");
  47. Dupa p2("drugiej");
  48. Dupa p3("trzeciej");
  49.  
  50. p3 = p1 + p2;
  51.  
  52.  
  53. std::cout << "hehe" << std::endl;
  54.  
  55. return 0;
  56. }
Add Comment
Please, Sign In to add comment