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

相关推荐
2401_82749999几秒前
代码随想录-图论28
算法·深度优先·图论
Tony Bai1 分钟前
AI 时代,Go 语言会“失宠”还是“封神”?—— GopherCon 2025 圆桌深度复盘
开发语言·人工智能·后端·golang
ValhallaCoder3 分钟前
Day51-图论
数据结构·python·算法·图论
寻星探路5 分钟前
【全景指南】JavaEE 深度解析:从 Jakarta EE 演进、B/S 架构到 SSM 框架群实战
java·开发语言·人工智能·spring boot·ai·架构·java-ee
晨非辰6 分钟前
Linux文件操作实战:压缩/传输/计算10分钟速成,掌握核心命令组合与Shell内核交互秘籍
linux·运维·服务器·c++·人工智能·python·交互
tc&7 分钟前
新虚拟机安装 Go 环境:问题总结与解决方案
开发语言·后端·golang
MSTcheng.7 分钟前
【C++】使用哈希表封装unordered_set和unordered_map!
c++·哈希算法·散列表·map/set封装
最低调的奢华8 分钟前
支持向量机和xgboost及卡方分箱解释
算法·机器学习·支持向量机
小镇学者8 分钟前
【python】python虚拟环境与pycharmIDE配置
开发语言·python
会员果汁9 分钟前
leetcode-887. 鸡蛋掉落-C
c语言·算法·leetcode