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;
}
相关推荐
冴羽yayujs13 小时前
JavaScript 9 个先有库再有 API 的故事
开发语言·javascript·ecmascript
回忆2012初秋13 小时前
.NET 8.0 实战:基于 MQTTnet 封装高可用的 MQTT 发布/订阅工具类
开发语言·mqtt·.net
djarmy13 小时前
一级函数头地址指针,(*p_func)的函数头的返回值,(*p_func)的函数头的参数列表
c++
阿Y加油吧13 小时前
两道位运算 / 摩尔投票经典题复盘:只出现一次的数字 & 多数元素
数据结构·算法·leetcode
小明同学0113 小时前
C++后端项目:统一大模型接入 SDK(一)
linux·c++·chatgpt
林夕0713 小时前
Qt 6.x 新特性概览:从 Qt 5 到 Qt 6 的升级之路
c++·qt6·跨平台开发
Evand J13 小时前
【课题推荐】三模型IMM交互式多模型滤波算法,匀速/左转/右转目标跟踪,附MATLAB代码测试结果
算法·matlab·目标跟踪·无人机·imm·多模型
油丶酸萝卜别吃13 小时前
JavaScript 深度合并函数 deepMerge 实现指南(附完整测试用例)
开发语言·javascript·测试用例
念恒1230613 小时前
Python(for循环进阶)
开发语言·python
05候补工程师13 小时前
【408狂飙·数据结构】核心考点深度复盘:数组地址计算、特殊矩阵压缩存储与树的五大性质解题直觉
数据结构·笔记·线性代数·考研·算法·矩阵