作者在 2009-08-21 11:56:28 发布以下内容
#include<iostream>
using std::cout;
using std::endl;
class base;
base* x; //全局指针
class base
{
public:
base(){
x=this; //this指向实际的对象,派生类产生后将指向派生类对象。
}
virtual void rprint(){
cout<<"this point to base"<<endl;
}
};
int main()
{
x->rprint();
return 0;
}
class derive:public base
{
public:
derive(){}
void rprint();
};
//全局应用对象
derive d1;
using std::cout;
using std::endl;
class base;
base* x; //全局指针
class base
{
public:
base(){
x=this; //this指向实际的对象,派生类产生后将指向派生类对象。
}
virtual void rprint(){
cout<<"this point to base"<<endl;
}
};
int main()
{
x->rprint();
return 0;
}
class derive:public base
{
public:
derive(){}
void rprint();
};
//全局应用对象
derive d1;
void derive::rprint()
{
cout<<"this point to derive"<<endl;
}
{
cout<<"this point to derive"<<endl;
}