引用块内容

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;
}C++构造、析构、继承、多态--一道题

相关文章:

  • 2021-05-18
  • 2022-02-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
  • 2021-08-17
相关资源
相似解决方案