【嵌入式学习】C++day0313

一、思维导图

二、习题

#include <iostream>

using namespace std;

class Per
{
private:
    string name;
    int age;
    float * high;
    float * weight;
public:
    //有参构造函数
    Per(string n,int a,float h,float w):name(n),age(a),high(new float (h)),weight(new float (w))
    {

    }

    //析构函数
    ~Per()
    {
        delete high;  //释放堆区空间
        delete weight;
    }

    //拷贝构造函数
    Per(const Per &other):name(other.name),age(other.age),high(new float (*(other.high))),weight(new float (*(other.weight)))
    {

    }

    //输出函数
    void show()
    {
    cout << "姓名:" << name << endl;
    cout << "年龄:" << age << endl;
    cout << "身高:" << *high << endl;
    cout << "体重:" << *weight << endl;
    }
};


class Stu
{
private:
    float sorce;
    Per p1;
public:
    Stu(float s,string name, int age,float high,float weight):sorce(s),p1(name,age,high,weight)
    {
        cout << "有参构造函数" << endl;
    }

    //拷贝构造函数
    Stu(const Stu &other):sorce(other.sorce),p1(other.p1)
    {}

    //输出函数
    void show()
    {
        cout << "成绩:" << sorce << endl;
    }
    Per p2=p1;

    //析构函数会自动调用Per的析构函数
};
int main()
{
    Stu s1(98,"张三",18,175,65);
    s1.show();
    s1.p2.show();
    return 0;
}

 

相关推荐

  1. 嵌入学习-ARM

    2024-03-14 05:58:02       43 阅读
  2. 嵌入学习-ARM

    2024-03-14 05:58:02       38 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-14 05:58:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-14 05:58:02       101 阅读
  3. 在Django里面运行非项目文件

    2024-03-14 05:58:02       82 阅读
  4. Python语言-面向对象

    2024-03-14 05:58:02       91 阅读

热门阅读

  1. Selenium WebDriver 中用于查找网页元素的两个方法

    2024-03-14 05:58:02       40 阅读
  2. Redis 键管理和数据库管理命令详解

    2024-03-14 05:58:02       45 阅读
  3. 小程序自定义表格组件

    2024-03-14 05:58:02       41 阅读
  4. 机器学习模型—分类回归树(CART)

    2024-03-14 05:58:02       38 阅读
  5. Qt的多线程类

    2024-03-14 05:58:02       37 阅读
  6. 背包问题大合集--算法模板

    2024-03-14 05:58:02       44 阅读
  7. 安塔利斯升级php8

    2024-03-14 05:58:02       40 阅读
  8. 动态规划--砝码称重

    2024-03-14 05:58:02       36 阅读