1135人加入学习
(3人评价)
C++编程系列 第三季类设计者的工具

制作于2018.6.26

价格 免费
课程还未发布,不允许加入和购买
#include <iostream>
#include "stdio.h"
#include "string"
using namespace std;
class B
{
public:
	int b_;
	B(int b = 0)
	{
		b_ = b;
		cout << "调用B的构造函数" << endl;
	}
};
class C1 :virtual public B
{
public:
	int c1_;
	C1(int b = 0, int c1 = 0) :B(b)
	{
		c1_ = c1;
		cout << "调用C1的构造函数" << endl;
	}
};
class C2 :virtual public B
{
public:
	int c2_;
	C2(int b = 0, int c2 = 0) :B(b)
	{
		c2_ = c2;
		cout << "调用C2的构造函数" << endl;
	}
};
class D :public C1, public C2
{
public:
	int d_;
	D(int b = 0, int c1 = 0, int c2 = 0, int d = 0) :B(b), C1(b, c1), C2(b, c2)
	{
		d_ = d;
		cout << "调D的构造函数" << endl;
	}
	void printf()
	{
		cout << "  C1.b_: " << C1::b_ << "  C2.b_: " << C2::b_ << "  c1_: " << c1_ << "  c2_: " << c2_ << "  d_: " << d_ << endl;
	}
};
class D2 : public C1, public C2
{
public:
	int d2_;
	D2(int b = 0, int c1 = 0, int c2 = 0, int d2 = 0) :B(b), C1(b, c1), C2(b, c2)
	{
		d2_ = d2;
		cout << "调用D2的构造函数" << endl;
	}
	void printf()
	{
		cout << "b_: " << b_ << "  c1_: " << c1_ << "  c2_: " << c2_ << "  d_: " << d2_ << endl;
	}
};
int main()
{
	D d = D(1, 2, 3, 4);
	d.printf();
	D2 d2 = D2(3, 4, 5, 6);
	d2.printf();


}

 

[展开全文]

授课教师

SIKI学院老师

课程特色

下载资料(1)
视频(56)

学员动态

AhoGe 完成了 502-总结2
AhoGe 开始学习 502-总结2
AhoGe 完成了 501-总结1
AhoGe 开始学习 501-总结1
AhoGe 完成了 403-类模板