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;
}
相关推荐
pystraf1 分钟前
模板分享:网络最小费用流
c++·算法·图论·网络流
AA-代码批发V哥2 分钟前
Java类一文分解:JavaBean,工具类,测试类的深度剖析
java·开发语言
GG不是gg6 分钟前
排序算法之高效排序:快速排序,归并排序,堆排序详解
数据结构·算法·排序算法
GG不是gg6 分钟前
排序算法之线性时间排序:计数排序,基数排序,桶排序详解
数据结构·算法·排序算法
亚里随笔16 分钟前
AlphaEvolve:LLM驱动的算法进化革命与科学发现新范式
人工智能·算法·llm·大语言模型
chilavert31817 分钟前
从RPA项目说说RPC和MQ的使用。
开发语言·qt·rpc·rabbitmq
thisiszdy17 分钟前
<C++> MFC自动关闭对话框(MessageBoxTimeout)
c++·mfc
越城19 分钟前
深入理解二叉树:遍历、存储与算法实现
c语言·数据结构·算法
绯樱殇雪27 分钟前
编程题 03-树2 List Leaves【PAT】
c++·pat考试
oioihoii28 分钟前
C++23 中的 ranges::fold_left:范围折叠算法
算法·c++23