C++构造、析构、继承、多态--一道题

xiaoxiao2021-02-28  41

引用块内容

include

using namespace std;

class A { public: A() { cout << “A constrution” << endl; } ~A() { cout << “A deconstrution” << endl; } void funA() { cout << “A::funA…” << endl; } virtual void funB() { cout << ” A::funB…” << endl; } };

class B : public A { public: B() { cout << “B constrution” << endl; } ~B() { cout << “B deconstrution” << endl; } void funA() { cout << “B::funA…” << endl; } virtual void funB() { cout << “B::funB…” << endl; }

};

int main() { A *a = new B(); B b; a->funA();//为什么?? a->funB(); b.funA(); b.funB(); delete a; //system(“pause”); return 0; }

转载请注明原文地址: https://www.6miu.com/read-1700060.html

最新回复(0)