Advertisement
Guest User

Laba_6(14)

a guest
Dec 10th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Text
  5. {
  6.     int Len;
  7.     char *Ref;
  8. public:
  9.     Text()
  10.     {
  11.         Len = 0;
  12.         Ref = new char[Len];
  13.     };
  14.     Text(char *Str)
  15.     {
  16.         Ref = new char[Len = strlen(Str) + 1];
  17.         strcpy_s(Ref, Len, Str);
  18.     }
  19.     ~Text()
  20.     {
  21.         delete Ref;
  22.     }
  23.     Text &operator =(const Text &);
  24.     void Out()
  25.     {
  26.         cout << " Out text = " << Ref << endl;
  27.     }
  28. };
  29.  
  30. Text &Text::operator =(const Text &Par)
  31. {
  32.     if (this == &Par) return *this;
  33.     else
  34.     {
  35.         delete Ref;
  36.         Ref = new char[strlen(Par.Ref) + 1];
  37.         strcpy_s(Ref, Len - 1, Par.Ref);
  38.     }
  39.     return *this;
  40. }
  41.  
  42. int main()
  43. {
  44.     char ch[] = "Text Text";
  45.     Text head(ch), tail;
  46.     tail = head;
  47.     tail.Out();
  48.  
  49.     system("pause");
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement