有以下类定义,写出该类的构造函数,析构函数,拷贝构造函数,要求,所有类对象的空间都是用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 &copy):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相关推荐

最新文章

  1. Topless eclipse导入myeclipse的web项目没法识别问题解决
  2. CBA Opportunity creation的性能跟踪
  3. 【开发者portal在线开发插件系列三】字符串 及 可变长度字符串
  4. ACM 整数划分(四)
  5. Web前端JavaScript笔记(7)ECMA6新增数组方法
  6. Spring Tool Suite插件的安装
  7. python三层for循环_Python基础入门-For循环
  8. findfont: Font family [‘Times New Roman‘] not found. Falling back to DejaVu Sans.
  9. excel二次开发c语言,用VBA进行Excel二次开发
  10. Python设计一个游戏类
  11. mysql模糊匹配关键字_MySQL 关键字模糊匹配,并按照匹配度排序
  12. 数据集介绍 - Matting and Segmentation
  13. C语言常见问题(9):Value stored to ret is never read
  14. JVM中类加载的时机
  15. 大数据处理问题及解决方法
  16. 严蔚敏《数据结构》——导航
  17. 面试官:RecyclerView布局动画原理了解吗?
  18. list集合移除指定元素
  19. MySQL 常用命令速查表:日常开发、求职面试必备良方!
  20. 详解Redis和Memcached

热门文章

  1. Android手机APK功耗、流量、内存测试方法
  2. Java生成随机不重复推广码邀请码
  3. 饼图不显示百分比(%),显示原始数据的处理
  4. Linux基础学习笔记(十二)——管道命令
  5. html实现商品列表2级分类,02-商品分类目录实现
  6. 意料之外也是情理之中,我的自由职业之旅
  7. 各国及牛叉公司组织架构图(Organization Chart)
  8. keyshot分辨率多少合适_KeyShot渲染设置技巧,教你KeyShotVR自定义设置
  9. 给这份并发编程宝典总结献出我的膝盖!
  10. Null pointer access: The variable al can only be null at this location问题的解决