c++---纯虚类

/*****************************************************************//**
 * \file   源.cpp
 * \brief  
 * 
 * \author Duan
 * \date   November 2022
 *********************************************************************/
#include<iostream>
#include<vector>

class BaseA
{
public:
    BaseA() {};
    ~BaseA() {};
    virtual int getValue() = 0;
private:

};

class ChildB : public BaseA
{
public:
    ChildB() {};
    ~ChildB() {};
    virtual int getValue() override;
private:

};

int ChildB::getValue() {
    std::cout << "i am ChildB ...\n";
    return 0;
}

class ChildC
{
public:
    ChildC(BaseA* aa_t) {
        aa = aa_t;
    };

    ~ChildC() {};
    int getValue() {
        aa->getValue();
        return 0;
    }
private:
    BaseA* aa;
};


int main() {
    ChildB * bb = new ChildB();
    ChildC cc(bb);
    cc.getValue();
    return 0;
}

 

posted @ 2022-11-11 18:41  玥茹苟  阅读(46)  评论(0编辑  收藏  举报