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;
}
原文地址:https://www.cnblogs.com/wucg/p/2356999.html