daily pastebin goal
55%
SHARE
TWEET

ех2

a guest Jun 25th, 2018 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Това го слагаш в .h
  2. #pragma once
  3. #ifndef _AStr_H
  4. #define _AStr_H
  5. #include <iostream>
  6. class AStr
  7. {
  8. private:
  9.     char n[20];
  10. public:
  11.     AStr(char[] = NULL);
  12.     AStr(const AStr&);
  13.     AStr& operator=(const AStr&);
  14.     ~AStr();
  15.  
  16.     virtual std::ostream& insert(std::ostream&) = 0;
  17. };
  18. std::ostream& operator<< (std::ostream&, const AStr &);
  19.  
  20. #endif
  21.  
  22. това го слагаш в .cpp
  23. #include "AStr.h"
  24. #include <iostream>
  25.  
  26. AStr::AStr(char c[])
  27. {
  28.     if (n != NULL)
  29.         strcpy_s(this->n, strlen(c) + 1, c);
  30. }
  31.  AStr::AStr(const AStr& rhs)
  32. {
  33.      if (rhs.n != NULL)
  34.      {
  35.          strcpy_s(n, strlen(rhs.n) + 1, rhs.n);
  36.      }
  37.  
  38. }
  39. AStr& AStr :: operator=(const AStr&rhs)
  40. {
  41.     if (this != &rhs) {
  42.         if (rhs.n != NULL)
  43.         {
  44.             strcpy_s(n, strlen(rhs.n) + 1, rhs.n);
  45.         }
  46.     }
  47.     return *this;
  48. }
  49.  
  50. AStr::~AStr()
  51. {
  52. }
  53.  
  54. std::ostream& AStr::insert(std::ostream& rhs)
  55. {
  56.     return rhs << n << std::endl;
  57. }
  58.  
  59. std::ostream& operator << (std::ostream& lhs, AStr& rhs) {
  60.     return rhs.insert(lhs);
  61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top