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

c++day3

#include <iostream>

using namespace std;

class Per
{
private:
    string name;
    int age;
    int *hight;
    int *weight;
public:
    Per()
    {
        cout << "无参构造函数" << endl;
    }
    Per(string name, int age, int *hight, int *weight):name(name),age(age),hight(new int(*hight)),weight(new int(*weight))
    {
        cout << "有参构造函数" << endl;
    }
    Per(const Per &other):name(other.name),age(other.age),hight(new int(*(other.hight))),weight(new int(*(other.weight)))
    {
        cout << "拷贝构造函数" << endl;
    }
    ~Per()
    {
        delete hight;
        delete weight;
        cout << "析构函数" << endl;
    }
    void show()
    {
        cout << "name: " << name << '\t';
        cout << "age: " << age << '\t';
        cout << "hight: " << *hight << '\t';
        cout << "weight: " << *weight << '\t';
    }
};

class Stu
{
private:
    float score;
    Per p1;
public:
    Stu()
    {
        cout << "无参构造函数" << endl;
    }
    Stu(float score, Per p1):score(score),p1(p1)
    {
        cout << "有参构造函数" << endl;
    }
    Stu(const Stu &other):score(other.score),p1(other.p1)
    {
        cout << "拷贝构造函数" << endl;
    }
    ~Stu()
    {
        cout << "析构函数" << endl;
    }
    void show()
    {
        p1.show();
        cout << "score: " << score << endl;
    }
};
int main()
{
    int w = 70;
    int h = 178;
    Per p1("张三", 18, &h, &w);
    Stu s1(95, p1);
    s1.show();
    Per p2(p1);
    Stu s2(s1);
    s2.show();
    return 0;
}

相关文章:

  • C#开发的OpenRA游戏之电力系统之二
  • 40V汽车级P沟道MOSFET SQ4401EY-T1_GE3 工作原理、特性参数、封装形式—节省PCB空间,更可靠
  • flutter出现entrypoint isn‘t within the current project
  • 高并发优化
  • 【SpringCloud】微服务技术栈入门6 - RestClient深入
  • GitHub基础
  • 数据结构与算法(七)--使用链表实现栈
  • 一、互联网技术-IP分片计算
  • HTML5+CSS3+移动web 前端开发入门笔记(一)
  • leetCode 15.三数之和 双指针解法
  • QT位置相关函数
  • java学习--day22(进程线程)
  • 【MySQL】Linux 中 MySQL 环境的安装与卸载
  • Traceview与TraceCompat 使用详解
  • 线性代数小例子
  • android studio导入android源码模块开发总结
  • node.js知识系列(1)-每天了解一点
  • K8S:K8S对外服务之Ingress
  • yolov7的bug,无法指定显卡(程序默认0号卡)
  • Ubuntu20.04 配置 yolov5_ros 功能包记录
  • 伊朗外长称正与美国进行“善意”的会谈
  • 卢正已任上海市司法局党委委员、副局长
  • 苏东坡:人生就是哈哈哈哈哈
  • 春秋航空:如果供应链持续改善、油价回落到合理水平,公司补充运力的需求将会增长
  • 中俄就应对美加征所谓“对等关税”等问题进行深入交流
  • 中非民间对话在赞比亚举行