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;
}
相关推荐
Navigator_Z1 天前
LeetCode //C - 1089. Duplicate Zeros
c语言·算法·leetcode
在繁华处1 天前
Java从零到熟练(四):面向对象基础
java·开发语言
Unbelievabletobe1 天前
解决了股票api接口盘后数据更新慢的问题
大数据·开发语言·python
cany10001 天前
C++ -- 可变参数模板
c++
不会C语言的男孩1 天前
C++ Primer 第2章:变量和基本类型
开发语言·c++
在繁华处1 天前
Java从零到熟练(三):流程控制
java·开发语言·python
云泽8081 天前
C++ 可调用对象通关指南:深度解析 Lambda 表达式、function 包装器与 bind 绑定器
开发语言·c++·算法
wlsh151 天前
Go 迭代器
算法
Tri_Function1 天前
简单图论大学习
c++
语戚1 天前
力扣 3161. 块放置查询:线段树解法(Java 实现)
java·算法·leetcode·面试·线段树·力扣·