#include <iostream>
#include<string.h> using namespace std;
class String
{
int length;
int i;
private:
char* m_data;//用于保护字符串
public:
String(const char *str=NULL)//普通构造函数
{
cout<<"调用了构造函数"<<endl;
if(str==NULL)
{
length=;
m_data=new char(); //指针指向这段空间
m_data[]='\0';
}
else
length=strlen(str);
m_data=new char(length+);
strcpy(m_data, str);
} String(const String &other)//拷贝构造函数
{
cout<<"调用了拷贝函数"<<endl; if(m_data)
{
delete []m_data;
int length=strlen(other.m_data);
m_data=new char[length+];
strcpy(m_data, other.m_data);
}
} ~String(void)//析构函数
{
cout<<"调用了析构函数"<<endl;
if (m_data) {
delete []m_data;
}
}
String &operator=(const String &other)//赋值函数
{ cout<<"调用了赋值函数"<<endl;
if (this==&other) //检查自赋值
return *this; delete []m_data;
int length=strlen(other.m_data);
m_data=new char[length+];
strcpy(m_data, other.m_data);
return *this;
} }; int main()
{
String str("abc");
String str1(str);
str.operator=(str);
}

最新文章

  1. Android环境变量配置
  2. Makefile中静态库,动态库的创建和使用以及解压缩命令
  3. JSP-JSTL学习
  4. Thinkphp 边学边用-验证码无意间犯的错
  5. ThinkPHP 购物商城网站(数据库中增删改查的功能实现)——————重点——————
  6. MySQL 命令行导出、导入Select 查询结果
  7. poj1992 数论
  8. Intro to Filtering with Network Monitor 3.0
  9. DzzOffice1.0 Beta2 全新安装图文教程及界面简单了解
  10. github/hexo搭建个人博客几个问题总结
  11. NOIP2014 寻找道路
  12. chmod 命令
  13. Struts2返回Json数据(使用Struts2插件)
  14. python_批量修改文件名
  15. OC工程调用Swift方法
  16. [Postman]创建第一个集合(2)
  17. vue-vuex状态管理-1
  18. 【Java入门提高篇】Day23 Java容器类详解(六)HashMap源码分析(中)
  19. 如何判断使用的是Lodop还是C-Lodop
  20. UVALive - 6442 (思维题)

热门文章

  1. java 获取系统变量(环境变量和环境变量)
  2. Visual Studio 2010/2013 查看DLL接口(函数)
  3. 采用oracle官方文件(11G)——初步Concept
  4. 使用C#实现顺序队列
  5. hdu Online Judge
  6. 读取上传的CSV为DataTable
  7. swiftSingleton模式
  8. 采用RedisLive监控Redis服务
  9. linux_常用压缩,解压缩命令
  10. 在Magento产品页面的使用jqZoom