#include <IOSTREAM.H>
//定义一个基类,模拟CWinApp
class Base
{
public:
	Base();
//	virtual void fn();/*测试虚函数结果:call the Derived's fn*/
	void fn();/*测试非虚函数结果:call the Base's fn*/
	Base *p;
};
Base::Base()
{
	p = this;//this指针指向哪一个对象?答:指向派生类对象dd
}

void Base::fn()
{
	cout << "call the Base's fn" << endl;
}

//定义一个派生类,模拟CTestApp
class Derived:public Base
{
public:
	void fn();
};
void Derived::fn()
{
	cout << "call the Derived's fn" << endl;
}
	
//定义一个派生类的全局对象,模拟theApp
Derived dd;

int main()
{
	(dd.p)->fn();
	return 0;
}

相关文章:

  • 2021-11-02
  • 2022-12-23
  • 2021-06-18
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
猜你喜欢
  • 2021-05-30
  • 2022-02-06
  • 2021-08-28
  • 2021-07-16
  • 2022-12-23
  • 2022-01-15
  • 2021-11-20
相关资源
相似解决方案