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

相关推荐
Jonathan Star6 分钟前
用Python轻松提取视频音频并去除静音片段
开发语言·python·音视频
给大佬递杯卡布奇诺23 分钟前
FFmpeg 基本数据结构 AVInputFormat 分析
数据结构·c++·ffmpeg·音视频
ゞ 正在缓冲99%…25 分钟前
leetcode2826.将三个组排序
算法·leetcode·动态规划
Evand J26 分钟前
【自适应粒子滤波MATLAB例程】Sage Husa自适应粒子滤波,用于克服初始Q和R不准确的问题,一维非线性滤波。附下载链接
开发语言·matlab·卡尔曼滤波·自适应滤波·非线性
给大佬递杯卡布奇诺27 分钟前
FFmpeg 基本数据结构 AVCodecContext分析
数据结构·c++·ffmpeg·音视频
qq_401700411 小时前
matlab学习
学习·算法·matlab
hd51cc1 小时前
C++ 类的学习(四) 继承
开发语言·c++·学习
紫荆鱼1 小时前
设计模式-命令模式(Command)
c++·后端·设计模式·命令模式
编码追梦人1 小时前
深耕 Rust:核心技术解析、生态实践与高性能开发指南
开发语言·后端·rust
2301_772093561 小时前
KVSTORE_Pain point_tuchuang_ROS2
java·开发语言·1024程序员节