Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Napis
- {
- private:
- char *nazwa;
- int dlugosc;
- public:
- Napis();
- Napis(const char * tab);
- ~Napis();
- Napis& operator= (const Napis &);
- Napis& operator+ (const Napis &);
- friend ostream & operator<< (ostream &, const Napis &);
- };
- Napis::Napis()
- {
- nazwa = new char[16 + 1];
- dlugosc = 0;
- memset(nazwa, 0, 16 + 1);
- }
- Napis::Napis(const char * tab)
- {
- dlugosc = (int)strlen(tab);
- nazwa = new char[dlugosc + 1];
- memset(nazwa, 0, dlugosc + 1);
- memcpy(nazwa, tab, dlugosc);
- }
- Napis::~Napis()
- {
- dlugosc = 0;
- delete[] nazwa;
- nazwa = NULL;
- }
- ostream& operator<<(ostream &out, const Napis &n)
- {
- return out << n.nazwa << endl;
- }
- Napis& Napis::operator= (const Napis &n1)
- {
- dlugosc = n1.dlugosc;
- nazwa = new char[dlugosc + 1];
- memset(nazwa, 0, dlugosc + 1);
- memcpy(nazwa, n1.nazwa, dlugosc);
- return *this;
- }
- Napis& Napis::operator+ (const Napis &n1)
- {
- int len = n1.dlugosc + dlugosc;
- char *buffer = new char[len + 1];
- memset(buffer, 0, len + 1);
- memcpy(buffer, nazwa, dlugosc);
- memcpy(buffer + dlugosc, n1.nazwa, n1.dlugosc);
- delete[] nazwa;
- nazwa = NULL;
- nazwa = buffer;
- return *this;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement