C++:day3

思维导图

练习题

cpp 复制代码
#include <iostream>
using namespace std;

class Per
{
private:
    string name;
    int age;
    int *height;
    double weight;

public:
    Per()
    {
        cout << "Per::无参构造函数" << endl;
    }
    Per(string name, int age, int height, double weight) : name(name), age(age), height(new int(height)), weight(weight)
    {
        cout << "Per::有参构造函数" << endl;
    }
    ~Per()
    {
        cout << "Per::析构函数" << endl;
        delete height;
        height = nullptr;
    }
};

class Stu
{
private:
    double score;
    Per p1;

public:
    Stu()
    {
        cout << "Stu::无参构造函数" << endl;
    }
    Stu(double score, string name, int age, int height, double weight) : score(score), p1(name, age, height, weight)
    {
        cout << "Stu::有参构造函数" << endl;
    }
    ~Stu()
    {
        cout << "Stu::析构函数" << endl;
    }
    void show()
    {
        cout << score << endl;
    }
};
int main(int argc, char const *argv[])
{
    Stu p(98, "葛飞飞", 23, 179, 86);
    p.show();
    return 0;
}
相关推荐
努力学习的小廉5 分钟前
深入了解linux系统—— 线程同步
linux·服务器·数据库·算法
数据爬坡ing8 分钟前
从挑西瓜到树回归:用生活智慧理解机器学习算法
数据结构·深度学习·算法·决策树·机器学习
luoganttcc9 分钟前
小鹏汽车 vla 算法最新进展和模型结构细节
人工智能·算法·汽车
sinat_6020353611 分钟前
模块与包的导入
运维·服务器·开发语言·python
恋雨QAQ13 分钟前
python函数和面向对象
开发语言·python
天雪浪子31 分钟前
Python入门教程之逻辑运算符
开发语言·python
骄傲的心别枯萎41 分钟前
RV1126 NO.16:通过多线程同时获取H264和H265码流
linux·c++·音视频·rv1126
落羽的落羽1 小时前
【C++】特别的程序错误处理方式——异常机制
开发语言·c++
空山新雨(大队长)1 小时前
C 语言第一课:hello word c
c++·c·exe
春蕾夏荷_7282977251 小时前
c++ 第三方库与个人封装库
c++·三方库