当前位置: 首页 > news >正文

析构函数,构造函数,赋值构造函数

#include <iostream>using namespace std;
class Per
{
private:string name;int age;double *hight;
public:Per(string name,int age,double hight):name(name),age(age),hight(new double(hight)){cout << "Per::的有参构造函数" << endl;}Per(const Per &other):name(other.name),age(other.age),hight(new double(*other.hight)){cout << "Per::拷贝构造函数" << endl;}~Per(){delete hight;hight = nullptr;cout << "Per::析构函数" << endl;}Per &operator=(const Per &other){if(this!=&other){this->name=other.name;this->age=other.age;this->hight=new double(*(other.hight));}cout << "Per::拷贝赋值函数" << endl;return *this;}};
class Stu
{
private:double score;Per p1;
public:Stu():score(0),p1("",0,0){cout << "Stu::无参构造函数" << endl;}Stu(double score,string name,int age,double hight):score(score),p1(name,age,hight){cout << "Stu::有参构造函数" << endl;}~Stu(){cout << "Stu::析构函数" << endl;}Stu(const Stu &other):score(other.score),p1(other.p1){cout << "Stu::拷贝赋值函数" << endl;}Stu &operator=(const Stu &other){if(this!=&other){this->score=other.score;this->p1=other.p1;}cout << "Stu::拷贝赋值函数" << endl;return *this;}
};
int main()
{Stu s;Stu s1(99.5,"张三",18,1.75);Stu s2(s1);s=s1;return 0;
}

http://www.dtcms.com/a/424355.html

相关文章:

  • iis5.1 建立网站医院 网站建设
  • port trunk pvid vlan vlan-id 概念及题目
  • 建设工程 法律 网站深圳人才网站建设
  • seo建站是什么意思在哪里找软件开发公司
  • 介绍Python对象类型
  • 随州网站建设哪家好wordpress 外观 自定义 没反应
  • 营销型网站建设 课程广告设计包括哪些方面
  • 西安网站建设哪个平台好安徽六安网
  • 网站顶端大图怎么做sem推广代运营
  • 八年级信息所用软件做网站网站建设怎样才能吸引顾客
  • 安卓基础006-视图
  • 建设标准 免费下载网站html5和h5的区别
  • 【展厅多媒体】大数据分析平台,展厅运营的“智慧眼”
  • 郑州网站建设公司锐客科技上海有名的设计工作室
  • 日期excel导入设置,导入表格实现日期批量打印
  • 再次使用xca软件生成自签证书
  • 【小白入门docker】创建Spring Boot Hello World应用制作Docker镜像并运行
  • 【Redis学习】String字符串
  • 项目实战:ecshop
  • 白城北京网站建设邵阳小学网站建设
  • SpringBoot 的配置文件与日志
  • 物联网技术与应用第三节课笔记
  • 【Java】P10 面向对象编程完全指南(S1-2 基础篇 包管理与导入)
  • C++ 特性 --内部类 模板类中取出来类类型问题
  • ip地址直接访问网站东莞市网络seo推广企业
  • 5090裸金属租用:捷智算助力企业数字化转型
  • 北京网站建设设计南阳网站建设哪家好
  • 大模型原理与实践:第一章-NLP基础概念完整指南_第1部分-概念和发展历史
  • 国企门户网站建设方案电子商务网站策划方案
  • 【Linux】cgdb调试工具的使用