关于虚函数继承问题.
#include<iostream>
using namespace std;
class base
{
public:
virtual void f1()
{
cout<<"f1 base"<<endl;
}
virtual void f2()
{
cout<<"f2 base"<<endl;
}
void f3()
{
cout<<"f3 base"<<endl;
}
};
class derive:public base
{
private:
void f1()
{
cout<<"f1 derive"<<endl;
}
void f2(int x)
{
cout<<"f2 derive"<<endl;
}
void f3()
{
cout<<"f3 derive"<<endl;
}
};
int main()
{
base ob1,*p;
derive ob2;
p=&ob1;
p->f1();
p->f2();
p->f3();
p=&ob2;
p->f1();
p->f2();
p->f3();
return 0;
}
为什么类derive的私有成员函数,也可以直接访问啊?