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

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

20170825_string构造函数、析构函数、拷贝构造函数以及重载赋值运算符

//string类的构造函数#include
#include
#include
using namespace std;//编写类String的构造函数、析构函数和赋值函数,已知类String的原型为: class String{public: String(const char *str = NULL); // 普通构造函数 String(const String &other); // 拷贝构造函数 ~String(void); // 析构函数 String & operator=(const String &other); // 赋值函数 private: char *m_data; // 用于保存字符串 };//1、普通构造函数String::String(const char *str) { if(str==NULL) { m_data = new char[1]; //得分点:对空字符串自动申请存放结束标志'\0'的空间 *m_data = '\0'; //加分点:对m_data加 NULL 判断 } else { int length = strlen(str); m_data = new char[length+1]; //若能加 NULL 判断则更好 if(m_data==nullptr) { cout<<"out of space!"<

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

你可能感兴趣的文章
Mysql 重置自增列的开始序号
查看>>
mysql 锁机制 mvcc_Mysql性能优化-事务、锁和MVCC
查看>>
MySQL 错误
查看>>
mysql 随机数 rand使用
查看>>
MySQL 面试题汇总
查看>>
MySQL 面试,必须掌握的 8 大核心点
查看>>
MySQL 高可用性之keepalived+mysql双主
查看>>
MySQL 高性能优化规范建议
查看>>
mysql 默认事务隔离级别下锁分析
查看>>
Mysql--逻辑架构
查看>>
MySql-2019-4-21-复习
查看>>
mysql-5.6.17-win32免安装版配置
查看>>
mysql-5.7.18安装
查看>>
MySQL-Buffer的应用
查看>>
mysql-cluster 安装篇(1)---简介
查看>>
mysql-connector-java.jar乱码,最新版mysql-connector-java-8.0.15.jar,如何愉快的进行JDBC操作...
查看>>
mysql-connector-java各种版本下载地址
查看>>
mysql-EXPLAIN
查看>>
MySQL-Explain的详解
查看>>
mysql-group_concat
查看>>