Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include "string.h"
  2. #include <cstring>
  3.  
  4. // Default constructor
  5. string::string()
  6. {
  7. }
  8.  
  9. // Constructor
  10. string::string(const char *text)
  11. {
  12.     // Create buffer
  13.     do
  14.     {
  15.         ++m_Size;
  16.     } while (text[m_Size - 1] != '\0');
  17.  
  18.     m_Buffer = new char[m_Size];
  19.  
  20.     // Store data to buffer
  21.     for (int i = 0; i < m_Size; i++)
  22.     {
  23.         m_Buffer[i] = text[i];
  24.     }
  25. }
  26.  
  27. // Copy constructor
  28. string::string(const string & other)
  29. {
  30.     m_Size = other.m_Size;
  31.     m_Buffer = new char[m_Size];
  32.  
  33.     for (int i = 0; i < m_Size; i++)
  34.     {
  35.         m_Buffer[i] = other.m_Buffer[i];
  36.     }
  37. }
  38.  
  39. // Destructor
  40. string::~string()
  41. {
  42.     delete[] m_Buffer;
  43. }
  44.  
  45. // Assignment operator
  46. void string::operator=(const string & other)
  47. {
  48.     m_Size = other.m_Size;
  49.     m_Buffer = other.m_Buffer;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement