博客
关于我
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/

你可能感兴趣的文章
Node-RED中使用Notification元件显示警告讯息框(温度过高提示)
查看>>
Node-RED中使用range范围节点实现从一个范围对应至另一个范围
查看>>
Node-RED中实现HTML表单提交和获取提交的内容
查看>>
Node-RED中将CSV数据写入txt文件并从文件中读取解析数据
查看>>
Node-RED中建立TCP服务端和客户端
查看>>
Node-RED中建立Websocket客户端连接
查看>>
Node-RED中建立静态网页和动态网页内容
查看>>
Node-RED中解析高德地图天气api的json数据显示天气仪表盘
查看>>
Node-RED中连接Mysql数据库并实现增删改查的操作
查看>>
Node-RED中通过node-red-ui-webcam节点实现访问摄像头并截取照片预览
查看>>
Node-RED中配置周期性执行、指定时间阶段执行、指定时间执行事件
查看>>
Node-RED安装图形化节点dashboard实现订阅mqtt主题并在仪表盘中显示温度
查看>>
Node-RED怎样导出导入流程为json文件
查看>>
Node-RED订阅MQTT主题并调试数据
查看>>
Node-RED通过npm安装的方式对应卸载
查看>>
node-request模块
查看>>
node-static 任意文件读取漏洞复现(CVE-2023-26111)
查看>>
Node.js 8 中的 util.promisify的详解
查看>>
node.js debug在webstrom工具
查看>>
Node.js RESTful API如何使用?
查看>>