标签:class UNC main void pac back cout turn 程序设计
#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
C++程序设计POJ》《WEEK6 多态与虚函数》《编程填空》
标签:class UNC main void pac back cout turn 程序设计
原文地址:https://www.cnblogs.com/focus-z/p/11100244.html