当前位置:编程学习 > C/C++ >>

隐藏基类的方法与调用

[cpp] 
#include <iostream> 
using namespace std; 
 
class mam{ 
    public: 
        void move() const {cout << "mammal move one step.\n"; } 
        void move(int distance)const { 
            cout << "mommal move"; 
            cout <<" " << distance << " " <<"steps." << endl; 
        } 
    protected: 
        int age; 
        int weight; 
}; 
 
class dog:public mam { 
    public: 
        void move()const { cout << "dog move 5 steps. " << endl; } 
}; 
 
int main() 

    mam animal; 
    dog fido; 
    animal.move(); 
    animal.move(2); 
    fido.move(); 
    fido.mam::move(10); //调用基类的方法。 
    return 0; 

补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,