Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "string.h"
- #include <cstring>
- // Default constructor
- string::string()
- {
- }
- // Constructor
- string::string(const char *text)
- {
- // Create buffer
- do
- {
- ++m_Size;
- } while (text[m_Size - 1] != '\0');
- m_Buffer = new char[m_Size];
- // Store data to buffer
- for (int i = 0; i < m_Size; i++)
- {
- m_Buffer[i] = text[i];
- }
- }
- // Copy constructor
- string::string(const string & other)
- {
- m_Size = other.m_Size;
- m_Buffer = new char[m_Size];
- for (int i = 0; i < m_Size; i++)
- {
- m_Buffer[i] = other.m_Buffer[i];
- }
- }
- // Destructor
- string::~string()
- {
- delete[] m_Buffer;
- }
- // Assignment operator
- void string::operator=(const string & other)
- {
- m_Size = other.m_Size;
- m_Buffer = other.m_Buffer;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement