【无标题】C++类型兼容规则

【无标题】C++类型兼容规则,第1张

题目描述:​根据main函数的内容倒推所涉及的几个类之间的关系,并完成这些的类的设计:

int main(){ Base1 b1; Base2 b2; Derived1 d1; Derived2 d2; Base1 *bp; bp=&b2; bp->doSomething();  //(1) cout< bp=&d1; bp->doSomething();  //(2) cout< bp=&d2; bp->doSomething();   //(3) cout< Base2 &br=d1; br.doSomething();   //(4) cout< d1.doSomething();   //(5) cout< d2.doSomething();   //(6) return 0; } 输入描述:无
#include
using namespace std;

class Base1
{
public:
	Base1(){}
	void doSomething()
	{
		cout << "Hello Base1" << endl;
	}
};
class Base2 :public Base1
{
public:
	Base2(){}
	void doSomething()
	{
		cout << "Hello Base2" << endl;;
	}
};
class Derived1 :public Base2
{
public:
	Derived1()
	{
		//Base1::doSomething();
		//Base2::doSomething();
	}
	void doSomething()
	{
		Base1::doSomething();
		Base2::doSomething();
		cout << "Hi Derived1"<

 

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/873006.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-13
下一篇2022-05-13

发表评论

登录后才能评论

评论列表(0条)