#include <iostream>
using namespace std ;
class Base
{
public:
Base *pB;
public:
Base()
{
pB = this;
}
virtual void output()//定义虚函数,是为了在运行时判断传入对象的指针类型
{
cout<<"Output Base!"<<endl;
}
};
class Derive : public Base
{
public:
void output()
{
cout<<"Output Derive!"<<endl;
}
};
Derive de;//如果实例化的是子类,则返回的是子类的指针
//Base de;//如果实例化的是父类,则返回的是父类的指针.
void main()
{
de.pB->output() ;
}
using namespace std ;
class Base
{
public:
Base *pB;
public:
Base()
{
pB = this;
}
virtual void output()//定义虚函数,是为了在运行时判断传入对象的指针类型
{
cout<<"Output Base!"<<endl;
}
};
class Derive : public Base
{
public:
void output()
{
cout<<"Output Derive!"<<endl;
}
};
Derive de;//如果实例化的是子类,则返回的是子类的指针
//Base de;//如果实例化的是父类,则返回的是父类的指针.
void main()
{
de.pB->output() ;
}