函数的覆盖和函数的隐藏
我学了函数的覆盖本来很明白了,学了函数的隐藏以后就迷糊了,怎么样区别它们两个呢?
多看看书..写写代码....
#include"iostream.h"
class father
{
public:
void demo1()
{
cout<<"this is father"<<endl;
}
virtual void demo2()
{
cout<<"this is virtual father"<<endl;
}
};
class son:public father
{
public:
void demo1()
{
cout<<"this is son"<<endl;
}
void demo2()
{
cout<<"this is virtual son"<<endl;
}
};
int main()
{
father a;
son b;
a.demo1();
b.demo1();
father &c=b;
c.demo1();
c.demo2();
return 1;
}