C++虚函数示例

#include <iostream>

using namespace std;

class P{
public:
	P * m_p;
	P(){
		this->m_p=this;
	}
	virtual void Intro(){
		cout<<"this is P"<<endl;
	}
};

class S:public P{
public :
	virtual void Intro(){
		cout<<"this is S"<<endl;
	}
};

S s;

int  main(){
	s.Intro();
	s.m_p->Intro();
	return 0;
}

 

posted @ 2012-02-18 13:44  庚武  Views(190)  Comments(0Edit  收藏  举报