#include <iostream> using namespace std; class A { public: A() { } virtual void func() { cout << "A::func" << endl; } virtual void fund() { cout << "A::fund" << endl; } void fun() { cout << "A::fun" << endl; } }; class B :public A { public: B() { func(); } void fun() { func(); } }; class C : public B { public: C() { } void func() { cout << "C::func" << endl; } void fund() { cout << "C::fund" << endl; } }; int main() { A * pa = new B(); pa->fun(); pa->fun(); // 不是多态,调用普通函数 B * pb = new C(); pb->fun(); while (1); return 0; }
//A::func
//A::fun
//A::func
//C::func
原文地址:https://www.cnblogs.com/focus-z/p/11100244.html
时间: 2024-11-08 01:47:09