您的位置:首页 > 编程语言 > C语言/C++

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

2018-01-14 22:45 267 查看
引用块内容

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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: