4月20号 C++

class String
{
  
  
public:
    String(char *str)
    {                
            int length = strlen(str);
            _str = new char[length + 1];
            strcpy(_str, str);
            size = length;        
    }
 
 
    String(String &other):_str(new char(other.size))
    {
  
  
 
 
    }
 
 
 
 
    ~String()
    {
  
  
        if (NULL != _str)
        {
  
  
            delete[] _str;
        }
    }
private:
    char *_str;
    size_t size;
};

猜你喜欢

转载自blog.csdn.net/weixin_73148834/article/details/130274481