Whatafuck先生(AB1B2)

#include <iostream>
using namespace std;
class B1{
public:
	void output();
};

class B2{
public:
	void output();
};

void B1::output()
{
	cout << "call the class B1" << endl;
}

void B2::output()
{
	cout << "call the class B2" << endl;
}

class A : public B1, public B2
{
public:
	void show();
};

void A::show()
{
	cout << "call the class A" << endl;
}

void main()
{
	A a;
	//a.output();  //该语句编译时会报错
	a.show();
}

 

#include<iostream>
using namespace std;
class animal
{
public:
	void eat()
	{
		cout << "animal eat" << endl;
	}
	void sleep()
	{
		cout << "animal sleep" << endl;
	}
	void breath()
	{
		cout << "animal breath" << endl;
	}
};

class fish :public animal
{
public:
	void breath()
	{
		cout << "fish bubble" << endl;
	}
};
void fn(animal *pAn)
{
	pAn->breath();
}

void main()
{
	animal *pAn;
	fish fh;
	pAn = &fh;
	fn(pAn);

	system("pause");
}

 

#include<iostream>
using namespace std;
class animal
{
public:
	void eat()
	{
		cout << "animal eat" << endl;
	}
	void sleep()
	{
		cout << "animal sleep" << endl;
	}
	virtual void breath()
	{
		cout << "animal breath" << endl;
	}
};

class fish :public animal
{
public:
	void breath()
	{
		cout << "fish bubble" << endl;
	}
};
void fn(animal *pAn)
{
	pAn->breath();
}

void main()
{
	animal *pAn;
	fish fh;
	pAn = &fh;
	fn(pAn);

	system("pause");
}

 

#include<iostream>
using namespace std;

void change(int& a, int& b);
void main()
{
	int x = 5;
	int y = 3;
	cout << "original x=" << x << endl;
	cout << "original y=" << y << endl;
	change(x, y);//此处如果用指针传递,则调用change(&x,&y),这样很容易让人迷惑,不知道交换的是x和y的值,还是x和y的地址?此处为引用,可读性就比指针要好

	cout << "changed x=" << x << endl;
	cout << "changed y=" << y << endl;

	system("pause");
}
//在change()函数的实现中,,采用了一个小算法,完成了a和b值的交换,
void change(int& a, int& b)
{
	a = a + b;
	b = a - b;
	a = a - b;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值