博客
关于我
20170825_string构造函数、析构函数、拷贝构造函数以及重载赋值运算符
阅读量:96 次
发布时间:2019-02-25

本文共 1151 字,大约阅读时间需要 3 分钟。

//string???????????????????????????//??????String::String(const char *str) {    if (str == NULL) {        //???????????????'\0'???        m_data = new char[1];        *m_data = '\0';    } else {        int length = strlen(str);        m_data = new char[length + 1];        //??? NULL ?????        if (m_data == nullptr) {            cout << "out of space!";            //???????????        }    }}//??????String::String(const String &other) {    //???????    m_data = new char(other.length() + 1);    memcpy(m_data, other.m_data, other.length());    m_data[other.length()] = '\0';}//????String::~String() {    //?????????    delete[] m_data;}//???????String &String::operator=(const String &other) {    //???????????????????    if (this == &other) {        return *this;    }    //?????????    delete[] m_data;    //?????????    m_data = new char(other.length() + 1);    memcpy(m_data, other.m_data, other.length());    m_data[other.length()] = '\0';    return *this;}

//?????//1. ?????????????????????????????//2. ???????????????//3. ????????????????//4. ???new?delete??????????????//5. ??????memcpy???????????//6. ????????????????unique_ptr???RAII??

转载地址:http://lzz.baihongyu.com/

你可能感兴趣的文章
opencv12-图像金字塔
查看>>
opencv13-基本阈值操作
查看>>
opencv14-自定义线性滤波
查看>>
opencv15-边缘处理
查看>>
opencv16-Sobel算子
查看>>
opencv17-laplance算子
查看>>
opencv18-canny检测算法
查看>>
opencv19-霍夫直线变化
查看>>
opencv2-矩阵掩膜操作
查看>>
opencv20-霍夫圆检测
查看>>
opencv21-像素重映射
查看>>
opencv22-直方图均衡化
查看>>
opencv23-直方图计算
查看>>
opencv24-直方图比较
查看>>
opencv25-直方图反向投影
查看>>
opencv26-模板匹配
查看>>
opencv27-轮廓发现
查看>>
opencv28-凸包
查看>>
opencv29-轮廓周围绘制矩形框和圆形框
查看>>
OpenCV3 install tutorial for Mac
查看>>