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 分钟前
LeetCode 热题 HOT100(一):哈希表与双指针入门(Go 实现)
算法·leetcode·职场和发展
学习中.........9 分钟前
并行 BPE 训练 与 手写 `Tokenizer`
人工智能·算法·机器学习·语言模型
宸津-代码粉碎机12 分钟前
告别手动Jar部署!生产级无损热部署方案,彻底解决OOM与更新失效问题
java·大数据·开发语言·人工智能·python
米码收割机13 分钟前
【移动】线上购物移动端网站(源码+文档)【独一无二】
java·开发语言·前端·python·django
小肝一下19 分钟前
多态(上)
android·开发语言·c++·vscode·多态·面向对象·伊蕾娜
科学实验家21 分钟前
动态规划2
算法·动态规划
无敌秋28 分钟前
python/c++/java上云
java·c++·python
imuliuliang10 小时前
关于数据结构在算法设计中的核心作用解析7
算法
code_pgf10 小时前
C++11 / C++14 / C++17 / C++20 新特性总结
c++·c++20
魔力女仆11 小时前
分享一个 JS 鼠标跟随贪吃蛇背景库
开发语言·javascript·计算机外设