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

相关推荐
艾莉丝努力练剑9 分钟前
【C语言16天强化训练】从基础入门到进阶:Day 6
c语言·数据结构·学习·算法
快去睡觉~1 小时前
力扣1005:k次取反后最大化的数组和
数据结构·算法·leetcode
smilejingwei1 小时前
数据分析编程第二步: 最简单的数据分析尝试
数据库·算法·数据分析·esprocspl
文火冰糖的硅基工坊2 小时前
[激光原理与应用-317]:光学设计 - Solidworks - 草图
开发语言·python·信息可视化·系统架构
草莓熊Lotso2 小时前
【C语言强化训练16天】--从基础到进阶的蜕变之旅:Day10
c语言·开发语言·经验分享·算法·强化
草明2 小时前
docker stats 增加一列容器名称的显示
java·开发语言·docker
He1955012 小时前
Go初级二
开发语言·后端·golang
张同学的IT技术日记2 小时前
详细实例说明+典型案例实现 对迭代法进行全面分析 | C++
算法
Coovally AI模型快速验证2 小时前
全景式综述|多模态目标跟踪全面解析:方法、数据、挑战与未来
人工智能·深度学习·算法·机器学习·计算机视觉·目标跟踪·无人机
risc-v@cn3 小时前
【在ubuntu下使用vscode打开c++的make项目及编译调试】
c++·vscode·ubuntu