Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Това го слагаш в .h
- #pragma once
- #ifndef _AStr_H
- #define _AStr_H
- #include <iostream>
- class AStr
- {
- private:
- char n[20];
- public:
- AStr(char[] = NULL);
- AStr(const AStr&);
- AStr& operator=(const AStr&);
- ~AStr();
- virtual std::ostream& insert(std::ostream&) = 0;
- };
- std::ostream& operator<< (std::ostream&, const AStr &);
- #endif
- това го слагаш в .cpp
- #include "AStr.h"
- #include <iostream>
- AStr::AStr(char c[])
- {
- if (n != NULL)
- strcpy_s(this->n, strlen(c) + 1, c);
- }
- AStr::AStr(const AStr& rhs)
- {
- if (rhs.n != NULL)
- {
- strcpy_s(n, strlen(rhs.n) + 1, rhs.n);
- }
- }
- AStr& AStr :: operator=(const AStr&rhs)
- {
- if (this != &rhs) {
- if (rhs.n != NULL)
- {
- strcpy_s(n, strlen(rhs.n) + 1, rhs.n);
- }
- }
- return *this;
- }
- AStr::~AStr()
- {
- }
- std::ostream& AStr::insert(std::ostream& rhs)
- {
- return rhs << n << std::endl;
- }
- std::ostream& operator << (std::ostream& lhs, AStr& rhs) {
- return rhs.insert(lhs);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement