C++4.2

#include <iostream>
 
using namespace std;
 
class A
{
public:
    int a;
    A(int a)
    {
        this->a = a;
        cout << "A有参构造" << endl;
    }
};
 
class B:virtual public A
{
public:
    int b;
    B(int b):A(1)
    {
        this->b = b;
        cout << "B有参构造" << endl;
    }
};
 
class C:virtual public A
{
public:
    int c;
    C(int c): A(1)
    {
        this->c = c;
        cout << "C有参构造" <<endl;
    }
};
 
class D:public B,public C
{
public:
    int d;
    D(int d):B(4),C(5),A(1)
    {
        this->d = d;
        cout << "D有参构造" << endl;
    }
};
 
int main()
{
    D d(5);
    return 0;
}

class Father
{
    int* p;
    const string name;
public:
    Father() :p(new int(0)),name("biu") {}
    Father(int p,const string name):p(new int(p)),name(name){}
    ~Father() { delete p; }
 
    Father(const Father& other):name(other.name)
    {
        this->p = new int;
    }
 
    Father& operator=(const Father& other)
    {
        *(this->p) = *(other.p);
        return *this;
    }
};
 
class Son :public Father
{
    int* age;
public:
    Son() :age(new int(19)) {}
    Son(int age) :age(new int(age)) {}
    ~Son() { delete age; }
    Son(const Son& other)
    {
        this->age = new int;
        *(this->age) = *(other.age);
    }
 
    Son& operator=(const Son& other)
    {
        *(this->age) = *(other.age);
    }
 
};

————————————————

                            版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
                        
原文链接:https://blog.csdn.net/qq_57107322/article/details/137255095

相关推荐

  1. c yuv422转yuv420p

    2024-04-02 10:24:02       33 阅读
  2. 学完Efficient c++ (44-45)

    2024-04-02 10:24:02       17 阅读
  3. 学完Efficient c++ (46-47)

    2024-04-02 10:24:02       21 阅读
  4. 《Effective Modern C++》- 极精简版 36-42

    2024-04-02 10:24:02       19 阅读
  5. C:2019-42真题408 循环队列

    2024-04-02 10:24:02       17 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-02 10:24:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-02 10:24:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-02 10:24:02       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-02 10:24:02       20 阅读

热门阅读

  1. 深入理解 C++ Lambda 表达式

    2024-04-02 10:24:02       14 阅读
  2. 【DevOps工具篇】安装 LDAP 管理 GUI PhpLdapAdmin

    2024-04-02 10:24:02       15 阅读
  3. Docker:使用MinIO搭建对象存储平台

    2024-04-02 10:24:02       16 阅读
  4. 在k8s中部署高可用程序实践和资源治理

    2024-04-02 10:24:02       17 阅读
  5. 【数据结构】二叉树

    2024-04-02 10:24:02       14 阅读
  6. Unity 读写Excel打包后无法运行可能的解决方案

    2024-04-02 10:24:02       19 阅读
  7. ubuntu 20.04 SD 卡分区类型 msdos 改为 GPT 的方法

    2024-04-02 10:24:02       15 阅读
  8. LeetCode热题Hot100 - 最长回文子串

    2024-04-02 10:24:02       19 阅读
  9. 探索信创之路:为何坚持自主创新

    2024-04-02 10:24:02       16 阅读
  10. C++ list

    C++ list

    2024-04-02 10:24:02      13 阅读
  11. HashMap 和 Hashtable 有什么区别?

    2024-04-02 10:24:02       17 阅读