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;
}
相关推荐
程序员学习随笔4 小时前
ext4 原理篇(三):日志子系统 Journal 深度剖析 —— 如何保障数据一致性?
linux·c++
OxyTheCrack4 小时前
【C++】一篇文章悲观锁与乐观锁与其思想在C++语言中的应用
linux·开发语言·数据库·c++·笔记
whycthe4 小时前
c++二叉树详解
数据结构·c++·算法
崇山峻岭之间4 小时前
matlab的FOC仿真
开发语言·matlab
默默学前端4 小时前
JavaScript 中 call、apply、bind 的区别
开发语言·前端·javascript
星辰_mya4 小时前
Fork/Join 框架与并行流:CPU 密集型的“分身术”
java·开发语言·面试
郝学胜-神的一滴4 小时前
循环队列深度剖析:从算法原理到C++实现全解析
开发语言·数据结构·c++·算法·leetcode
Via_Neo4 小时前
接雨水问题 + 输入优化
java·开发语言·算法
所谓伊人,在水一方3334 小时前
【Python数据可视化精通】第9讲 | 实时数据流可视化
开发语言·python·信息可视化·数据分析·pandas
吃鱼不吐刺.4 小时前
阻塞队列。
java·开发语言