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;
}
相关推荐
难以触及的高度13 分钟前
Java for循环完全指南:从基础到高性能实践
java·开发语言
wadesir14 分钟前
用Python实现ggplot2风格绘图(零基础入门Seaborn与Matplotlib美化技巧)
开发语言·python·matplotlib
油炸自行车28 分钟前
【Qt】Qt Creator Debug模式提示“缺少 Windows CDB 调试器配套的扩展组件“”
开发语言·windows·qt
budingxiaomoli31 分钟前
多线程(三)
java·开发语言
VBA633736 分钟前
VBA之Excel应用第十节:用Union和Intersect方法获得单元格区域
开发语言·自然语言处理
klzdwydz1 小时前
注解与反射
java·开发语言
ULTRA??1 小时前
C语言简化版本开辟动态内存的万能MALLOC宏封装
c语言·开发语言
2401_861277551 小时前
func(int* num)的实现是*num=2或者int a=3,num=&a都可以吗
c语言·c++
talenteddriver1 小时前
java: 分页查询(自用笔记)
java·开发语言
繁华似锦respect1 小时前
lambda表达式中的循环引用问题详解
java·开发语言·c++·单例模式·设计模式·哈希算法·散列表