我用的是public继承,但是为何子类的函数不是public的呢?
我用的是public继承,但是为何子类的函数不是public的呢?#include <iostream.h>
class base;
base * pbase;
class base
{
public:
base()
{
pbase=this;
}
virtual void fn()
{
cout<<"base"<<endl;
}
};
class derived:public base
{
void fn()
{
cout<<"derived"<<endl;
}
};
derived aa; //全局变量
void main()
{
derived my1;
my1.fn();
}