嵌入式4-25

  1. 整理思维导图
  2. 在课上练习的基础上,完成拷贝赋值函数
  3. 完成下列类

#include <iostream>
using namespace std;

class person
{
    string name;
    int age;
    char sex;
public:
    int *p;
    person()
    {
        cout<<"person无参构造"<<endl;
    };
    person(const string n,int a,char s):name(n),age(a),sex(s)
    {
        cout<<"person有参构造"<<endl;
    }
    person(const person &other):p(new int(*(other.p)))
    {
        this->name=other.name;
        this->age=other.age;
        this->sex=other.sex;
    }
    person &operator=(const person &other)
    {
        if(&other!=this)
        {
            this->name=other.name;
            this->age=other.age;
            this->sex=other.sex;
        }
        return *this;
    }
    void show()
    {
        cout<<name<<age<<sex<<endl;
    }
    ~person()
    {
        delete p;
    }
};
class stu
{
    person p;
    double *score;
public:
    stu():p("张三",18,'m'),score(new double)
    {
        cout<<"stu无参构造"<<endl;
    }
    stu(const string n,int a,char s,double score):p(n,a,s),score(new double(score))
    {
        cout<<"stu有参构造"<<endl;
    }
    void show()
    {
        p.show();
        cout<<*score<<endl;
    }
    ~stu()
    {
        delete score;
    }
};

int main()
{
    person p1("zhangsan",18,'m');
    person p2(p1);
    person p3;
    p3=p2;
    p1.show();
    p2.show();
    p3.show();
    cout<<(p1.p)<<' '<<(p2.p)<<' '<<(p3.p)<<endl;
    return 0;
}

相关推荐

  1. 嵌入学习日记 25

    2024-04-26 04:30:01       37 阅读
  2. 嵌入开发】29

    2024-04-26 04:30:01       49 阅读
  3. 嵌入24——IO

    2024-04-26 04:30:01       52 阅读
  4. 嵌入学习日记 27

    2024-04-26 04:30:01       42 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-26 04:30:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-26 04:30:01       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-26 04:30:01       82 阅读
  4. Python语言-面向对象

    2024-04-26 04:30:01       91 阅读

热门阅读

  1. vue 手写手动轮播 且图片宽度不一样

    2024-04-26 04:30:01       36 阅读
  2. C#中=> “Lambda运算符”

    2024-04-26 04:30:01       78 阅读
  3. 关于Gitea 的简单介绍

    2024-04-26 04:30:01       35 阅读
  4. 反序列bit

    2024-04-26 04:30:01       31 阅读
  5. gitlab 16.2.4 恢复

    2024-04-26 04:30:01       33 阅读
  6. golang面试题:拷贝大切片一定比小切片代价大吗?

    2024-04-26 04:30:01       133 阅读
  7. “生成元”问题——穷举生成“查找表”

    2024-04-26 04:30:01       186 阅读
  8. C++之const

    2024-04-26 04:30:01       64 阅读
  9. 阿里云直播推流和播流地址的生成方法PHP

    2024-04-26 04:30:01       36 阅读
  10. Unity构建详解(10)——Unity构建流程

    2024-04-26 04:30:01       34 阅读