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;
}
相关推荐
2401_841495642 小时前
【计算机视觉】基于复杂环境下的车牌识别
人工智能·python·算法·计算机视觉·去噪·车牌识别·字符识别
Jonkin-Ma2 小时前
每日算法(1)之单链表
算法
ONE_PUNCH_Ge3 小时前
Go 语言变量
开发语言
幼稚园的山代王3 小时前
go语言了解
开发语言·后端·golang
晚风残3 小时前
【C++ Primer】第六章:函数
开发语言·c++·算法·c++ primer
杨云强3 小时前
离散积分,相同表达式数组和公式
算法
地平线开发者3 小时前
征程 6 | BPU trace 简介与实操
算法·自动驾驶
满天星83035773 小时前
【C++】AVL树的模拟实现
开发语言·c++·算法·stl
weixin_456904273 小时前
基于.NET Framework 4.0的串口通信
开发语言·c#·.net
ss2733 小时前
手写MyBatis第107弹:@MapperScan原理与SqlSessionTemplate线程安全机制
java·开发语言·后端·mybatis