• 自考新教材--p248


    源程序:

    //

    //  main.cpp

    //  virtualfunction

    //

    //  Created by duanqibo on 2020/1/9.

    //  Copyright © 2020年 duanqibo. All rights reserved.

    //

    #include <iostream>

    using namespace std;

    class A

    {

    public:

        virtual void Print()

        {

            cout<<"A::Print"<<endl;

        }

    };

    class B:public A

    {

    public:

        virtual void Print()

        {

            cout<<"B::Print"<<endl;

        }

    };

    class D:public A

    {

    public:

        virtual void Print(){

            cout<<"D::Print"<<endl;

        }

    };

    class E:public B

    {

    public:

        virtual void Print()

        {

            cout<<"E::print"<<endl;

        }

    };

    int main()

    {

        A a;B b;D d;E e;

        A *pa = &a;

        B *pb = &b;

        pa->Print();

        pa = pb;

        pa->Print();

        pa = &d;

        pa->Print();

        pa = &e;

        pa->Print();

        return 0;

    }

     运行结果:

  • 相关阅读:
    Nginx调试入门
    Nginx自动安装脚本
    Centos7.3自动化脚本安装MySQL5.7
    复制多行内容到文本
    Windows常用命令
    C++笔试题
    loadrunner和QTP视频教程汇总
    mysql-connector-java-5.1.22下载
    struts学习笔记
    Hibernate原理
  • 原文地址:https://www.cnblogs.com/duanqibo/p/12173941.html
Copyright © 2020-2023  润新知