⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 virtualdemo.cpp

📁 《基于Symbian OS的手机开发与应用实践》这本书的配套源码。
💻 CPP
字号:
// VirtualDemo.cpp : 虚函数演示
// 

#include <stdio.h>

class ShapeVirtual
{
public:
	int x;
	virtual void ShowName() 
	{
		printf("\nShapeVirtual对象的ShowName函数被调用\n");
		printf("x=%d\n", x);
	}

	virtual void ShowName(int a) 
	{
		printf("\nShapeVirtual对象的ShowName(int a)函数被调用\n");
		printf("x=%d\n", x);
	}

	void func1() {}

	virtual void func2() {}
};

//类PointVirtual继承于类ShapeVirtual
//
class PointVirtual : public ShapeVirtual
{
public:
	//int x;
	using ShapeVirtual::ShowName;
	void ShowName() 
	{
		printf("\nPointVirtual对象的ShowName函数被调用\n");
		printf("x=%d\n", x);
	}
};

int main(int argc, char* argv[])
{
	//创建ShapeHide对象
	ShapeVirtual *s = new ShapeVirtual();
	s->x = 1;
	s->ShowName();
	s->ShowName(1);
	//创建PointHide对象
	PointVirtual *p = new PointVirtual();
	p->x = 2;
	p->ShowName();
	p->ShowName(1);

	//s指向ShapeVirtual对象
	delete s;
	//让ShapeVirtual对象指针,指向PointVirtual对象
	s = p;
	
	s->ShowName();
	s->ShowName(1);

	delete p;
	s = NULL;
	p = NULL;
	
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -