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;
}
相关推荐
Fantasydg14 分钟前
DAY 38 leetcode 15--哈希表.三数之和
算法·leetcode·散列表
编程绿豆侠17 分钟前
力扣HOT100之链表:19. 删除链表的倒数第 N 个结点
算法·leetcode·链表
ゞ 正在缓冲99%…18 分钟前
leetcode274.H指数
java·算法·leetcode
程序员小杰@19 分钟前
AI前端组件库Ant DesIgn X
开发语言·前端·人工智能
liulun1 小时前
Windows注册鼠标钩子,获取用户选中的文本
c++·windows·qt
Aerkui1 小时前
Python高阶函数-eval深入解析
开发语言·python
小诸葛的博客2 小时前
client-go如何监听自定义资源
开发语言·后端·golang
入 梦皆星河2 小时前
go原理刨析之channel
开发语言·后端·golang
Pandaconda2 小时前
【新人系列】Golang 入门(十二):指针和结构体 - 上
开发语言·后端·golang·go·指针·结构体·后端开发
6<72 小时前
【go】类型断言
开发语言·后端·golang