Work20230606
2024-05-15 20:36:48
有以下类定义,写出该类的构造函数,析构函数,拷贝构造函数,要求,所有类对象的空间都是用new动态申请。
class stu
string name;int age;
int score;int *high;
};
#include <iostream>
#include <string.h>
using namespace std;
class Stu
{
private:string name;int age;int score;int *high;
public://无参构造函数Stu(){cout<<"无参构造函数"<<endl;}//有参构造函数Stu(string name1,int age1,int score1,int *high1){this->name=name1;this->age=age1;this->score=score1;this->high=high1;cout<<"有参构造函数"<<endl;}//析构函数~Stu(){cout <<"析构函数"<<endl;}//拷贝构造函数Stu(Stu ©):name(copy.name),age(copy.age),score(copy.score),high(copy.high){this->high = new int(*(copy.high));cout<<"拷贝函数"<<endl;}void show(){cout<<name<<" "<<age<<" "<<score<<" "<<high<<" "<<*high<<endl;}
};int main()
{string *name=new string("zhang");int *age=new int(10);int *score=new int(100);int *high=new int(150);//无参构造Stu stu0;stu0.show();//有参构造Stu stu1(*name,*age,*score,high);stu1.show();//拷贝构造Stu stu2=stu1;stu2.show();delete name;delete age;delete score;delete high;}
Work20230606相关推荐
最新文章
- Topless eclipse导入myeclipse的web项目没法识别问题解决
- CBA Opportunity creation的性能跟踪
- 【开发者portal在线开发插件系列三】字符串 及 可变长度字符串
- ACM 整数划分(四)
- Web前端JavaScript笔记(7)ECMA6新增数组方法
- Spring Tool Suite插件的安装
- python三层for循环_Python基础入门-For循环
- findfont: Font family [‘Times New Roman‘] not found. Falling back to DejaVu Sans.
- excel二次开发c语言,用VBA进行Excel二次开发
- Python设计一个游戏类
- mysql模糊匹配关键字_MySQL 关键字模糊匹配,并按照匹配度排序
- 数据集介绍 - Matting and Segmentation
- C语言常见问题(9):Value stored to ret is never read
- JVM中类加载的时机
- 大数据处理问题及解决方法
- 严蔚敏《数据结构》——导航
- 面试官:RecyclerView布局动画原理了解吗?
- list集合移除指定元素
- MySQL 常用命令速查表:日常开发、求职面试必备良方!
- 详解Redis和Memcached
热门文章
- Android手机APK功耗、流量、内存测试方法
- Java生成随机不重复推广码邀请码
- 饼图不显示百分比(%),显示原始数据的处理
- Linux基础学习笔记(十二)——管道命令
- html实现商品列表2级分类,02-商品分类目录实现
- 意料之外也是情理之中,我的自由职业之旅
- 各国及牛叉公司组织架构图(Organization Chart)
- keyshot分辨率多少合适_KeyShot渲染设置技巧,教你KeyShotVR自定义设置
- 给这份并发编程宝典总结献出我的膝盖!
- Null pointer access: The variable al can only be null at this location问题的解决