/*****************************************************************//** * \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; }
标签:BaseA,int,c++,getValue,---,public,ChildB,private,纯虚类 From: https://www.cnblogs.com/lovebay/p/16881451.html