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

你可能感兴趣的文章
NodeJs学习笔记002--npm常用命令详解
查看>>
nodejs学习笔记一——nodejs安装
查看>>
vue3+Element-plus icon图标无法显示的问题(已解决)
查看>>
NodeJS实现跨域的方法( 4种 )
查看>>
nodejs封装http请求
查看>>
nodejs常用组件
查看>>
nodejs开发公众号报错 40164,白名单配置找不到,竟然是这个原因
查看>>
Nodejs异步回调的处理方法总结
查看>>
NodeJS报错 Fatal error: ENOSPC: System limit for number of file watchers reached, watch ‘...path...‘
查看>>
nodejs支持ssi实现include shtml页面
查看>>
Nodejs教程09:实现一个带接口请求的简单服务器
查看>>
nodejs服务端实现post请求
查看>>
nodejs框架,原理,组件,核心,跟npm和vue的关系
查看>>
Nodejs概览: 思维导图、核心技术、应用场景
查看>>
nodejs模块——fs模块
查看>>
Nodejs模块、自定义模块、CommonJs的概念和使用
查看>>
nodejs生成多层目录和生成文件的通用方法
查看>>
nodejs端口被占用原因及解决方案
查看>>
Nodejs简介以及Windows上安装Nodejs
查看>>
nodejs系列之express
查看>>