Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Text
- {
- int Len;
- char *Ref;
- public:
- Text()
- {
- Len = 0;
- Ref = new char[Len];
- };
- Text(char *Str)
- {
- Ref = new char[Len = strlen(Str) + 1];
- strcpy_s(Ref, Len, Str);
- }
- ~Text()
- {
- delete Ref;
- }
- Text &operator =(const Text &);
- void Out()
- {
- cout << " Out text = " << Ref << endl;
- }
- };
- Text &Text::operator =(const Text &Par)
- {
- if (this == &Par) return *this;
- else
- {
- delete Ref;
- Ref = new char[strlen(Par.Ref) + 1];
- strcpy_s(Ref, Len - 1, Par.Ref);
- }
- return *this;
- }
- int main()
- {
- char ch[] = "Text Text";
- Text head(ch), tail;
- tail = head;
- tail.Out();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement