美文网首页
2018-08-09

2018-08-09

作者: 流风逐云 | 来源:发表于2018-08-09 18:18 被阅读0次

    include <iostream>

    using namespace std;

    class Base{
    public:
    virtual void virtualFoo1(){
    cout << "Base::virtualFoo1 called" << endl;
    // Foo1();
    }
    virtual void virtualFoo2(){ cout << "Base::virtualFoo2 called" << endl; }
    void Foo1(){
    cout << "Base::Foo1 called " << endl;
    virtualFoo2();
    Foo2();
    }
    void Foo2(){
    cout << "Base::Foo2 called " << endl;
    }
    };

    class Derived : public Base{
    public:
    virtual void virtualFoo1(){
    cout << "Derived::virtualFoo1 called" << endl;
    Foo1();
    }
    virtual void virtualFoo2(){
    cout << "Derived::virtualFoo2 called" << endl;
    Foo2();
    }
    void Foo1(){
    cout << "Derived::Foo1 called " << endl;
    virtualFoo2();

    }
    void Foo2(){
        cout << "Derived::Foo2 called " << endl;
    }
    

    };

    int main(){
    Base * pb = new Derived;
    //Base * pb = new Base;
    pb->virtualFoo1();
    cout <<"== == == == == == ==" << endl;
    pb->Foo1();
    system("pause");
    }

    相关文章

      网友评论

          本文标题:2018-08-09

          本文链接:https://www.haomeiwen.com/subject/rivcbftx.html