博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[C++] Deep copy ,Shallow copy, copy constructor,"="
阅读量:7082 次
发布时间:2019-06-28

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

Deep copy ,Shallow copy, copy constructor,"="

Dog.h

#pragma onceclass Dog{public:    char *name;    Dog();    Dog(const Dog &it);    ~Dog();    void operator =(const Dog &it);};

 

Dog.cpp

 

#include "Dog.h"#include
#include
using namespace std;//ConstructorDog::Dog(){ name = new char[20]; memset(name,0,sizeof(name)); strcpy(name,"xiaohuang"); cout << "dog" << endl;}//DestructorDog::~Dog(){ delete []name; cout << "~dog" << endl;}// copy constructorDog::Dog(const Dog &it){ name = new char[20]; memset(name, 0, sizeof(name)); strcpy(name, it.name); cout << "copy dog" << endl;}// overload = void Dog:: operator =(const Dog &it){ strcpy(name, it.name); cout << " = " << endl;}

 

main.cpp

#include"Dog.h""using namespace std;void test(){    Dog d1;    Dog d2 = d1;    Dog d3;    d3 = d1;}void main(){        test();    system("pause");}

 

转载于:https://www.cnblogs.com/tianhangzhang/p/4904934.html

你可能感兴趣的文章
iOS少用的框架
查看>>
cdn
查看>>
TypeScript基础入门之JSX(二)
查看>>
C4D操作 延迟 ,卡顿罕见状况解决方案。
查看>>
面向对象二次整理(基础,属性引用,方法引用.绑定方法)
查看>>
[C++参考]私有成员变量的理解
查看>>
学习该有的思维方式
查看>>
Linux:查看磁盘空间占用情况
查看>>
redis发布订阅
查看>>
dubbo+zookeeper
查看>>
3D打印材料的发展现状(1)
查看>>
GPGPU之应用于Mapped Reduced
查看>>
html dom的nodetype值介绍,HTML DOM nodeType用法及代码示例
查看>>
html怎么对多个td应用样式,html – 如何将样式类应用于td类?
查看>>
Proxmox集群ceph报“ceph 1pg inconsistent”错误解决备忘
查看>>
多级菜单系统安装维护shell脚本实现企业级案例
查看>>
那些年,我玩过的操作系统
查看>>
Lync Server 2013标准版升级Skype for Business Server 2015实战(上)
查看>>
新浪、万网前系统架构师高俊峰:统一监控报警平台架构设计思路
查看>>
2011-9-25俱乐部活动
查看>>