// 常成员函数可以被重写
// 静态成员不可以被重写,因为它属于对象
// 虚函数具有多态性
#include
using namespace std;
class a{
public :
void m() const{
cout<<"eee"<<endl;
}
virtual void v(){
cout<<"a_virtual"<<endl;
}
static void t(){
cout<<"a::t()"<<endl;
}
};
class a1:public a{
public:
void m() const{
cout<<"eeexxx"<<endl;
}
virtual void v(){
// 虚函数同名同参数是基类如果是虚函数,派生类中也为虚函数,规范写法加上virtual
cout<<"a1_virtual"<<endl;
}
static void t(){
cout<<"a1::t()"<<endl;
}
};
int main(){
// 虚成员函数运行时多态性
a *t = new a1;
t->v();
// a1::t()
delete t;
// 删除单个存储空间,如果删除数组需要 delete []t;因为有new所以需要delete
a::t();
// 使用静态成员函数
a1::t();
// 使用静态成员函数
return 0;
}