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

相关推荐
Hi李耶3 分钟前
【LeetCode】557.反转字符串中的单词 III
算法·leetcode·职场和发展
yyy(十一月限定版)5 分钟前
016【入门】双端队列
数据结构·c++
深蓝学院10 分钟前
机器人学习算法五大体系详解:模仿、强化、多模态、持续学习……
算法·机器人
2401_8582861131 分钟前
OS82.【Linux】设计线程池
java·linux·运维·服务器·开发语言·算法·线程池
数据知道36 分钟前
IDOR 不安全的直接对象引用:API 越权实战检测
java·开发语言·网络·安全·网络安全
c238561 小时前
# Mini OJ — 项目详解文档
开发语言·数据库·c++
Epiphany.5561 小时前
找到所有好字符串(记忆化搜索+KMP)(里面含KMP模板,用来入门)
算法
2401_894915531 小时前
Geo 优化源码部署常见报错排查:连接失败、地图加载、地域词失效解决方案
服务器·开发语言·python·安全·php
c238561 小时前
C/C++每日一练20
c语言·开发语言·c++
坚持编程的菜鸟1 小时前
模拟实现strncpy
c语言·算法·模拟实现strncpy