Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <cassert>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. class TABLICA{
  8. private:
  9. char *p;
  10. public:
  11.  
  12. TABLICA()
  13. {
  14. p = new char[strlen("domyslny")+1];
  15. assert(p);
  16. strcpy(p,"domyslny");
  17. cout<<"Konstruktor (bezparametrowy) domyslny"<<endl<<endl;
  18. }
  19.  
  20. TABLICA(/*const*/char * tab)
  21. {
  22. p = new char[strlen(tab)+1];
  23. assert(p);
  24. strcpy(p,tab);
  25. cout<<"Konstruktor"<<endl<<endl;
  26. }
  27.  
  28. TABLICA(/*const*/ TABLICA & kopia)
  29. {
  30. p = new char[strlen(kopia.p)+1];
  31. assert(p);
  32. strcpy(p, kopia.p);
  33. cout<<"Konstruktor kopiujacy"<<endl<<endl;
  34. }
  35.  
  36. TABLICA & operator=(/*const*/ TABLICA & kopia)
  37. //lub
  38. //void operator=(/*const*/ TABLICA & kopia)
  39. {
  40. p = new char[strlen(kopia.p)+1];
  41. assert(p);
  42. strcpy(p, kopia.p);
  43. cout<<"Operator przypisania"<<endl<<endl;
  44. }
  45.  
  46. ~TABLICA()
  47. {
  48. delete [] p;
  49. cout<<"Destruktor"<<endl;
  50. }
  51. };
  52.  
  53. int main()
  54. {
  55. char tab[] = "Avatar";
  56.  
  57. TABLICA t0;
  58. TABLICA t1(tab);
  59. TABLICA t2 = t1;
  60.  
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement