015_linuxC++之_覆写

(一)覆写:就是子类继承父类,但是子类和父类中都有同样的函数,程序调用的是子类中的函数

 1 #include <iostream>
 2 using namespace std;
 3 class Father{
 4 public:
 5     void is_kill(void){
 6         cout<<"father's it skill"<<endl;
 7     }
 8 };
 9 
10 class Son_public:public Father{
11 public:
12     void is_kill(void){
13         cout<<"Son's it skill"<<endl;
14     }
15     
16 };
17 
18 int main(int argc, char **argv)
19 
20 {
21     Son_public S;
22     S.is_kill();
23 }
View Code

运行结果

猜你喜欢

转载自www.cnblogs.com/luxiaoguogege/p/9693825.html
今日推荐