zoukankan      html  css  js  c++  java
  • c++语法(3)

    子类覆盖父类的成员函数:

    #include "stdafx.h"
    #include "iostream"
    
    class CAnimal
    {
    protected:
        int m_Age;
        int m_Weight;
    public:
        void move();
    };
    
    class CDog:public CAnimal
    {
    public:
        void move();
    };
    
    void CAnimal::move()
    {
        printf("animal is moving");
    }
    
    void CDog::move()
    {
        printf("dog is moving");
    }
    
    int main(int argc, char* argv[])
    {
        CDog dog;
        dog.move();             //子类调用自身的move方法,父类的被覆盖掉
        std::cout<<std::endl;
        dog.CAnimal::move();    //子类调用父类的成员函数
        return 0;
    }
  • 相关阅读:
    sql number类型和varchar2类型
    B
    E
    D
    B
    A
    第三课 选区
    第二课 新建文件与图层
    第一课 界面认识
    CSS命名规则
  • 原文地址:https://www.cnblogs.com/qiangua/p/3478813.html
Copyright © 2011-2022 走看看