除了可以从派生类重写的方法中调用之外,纯虚函数似乎不能在任何地方调用!那么,它的身体有什么用呢?例如。
class base
{
public:
virtual void fun()=0
{
cout<<"I have been called from derived class"<<endl;
}
};
class derived:public base
{
public:
void fun()
{
cout<<"I am the derived class"<<endl;
base::fun();
}
};
void main()
{
derived d;
d.fun();
}