📜  C ++ |继承|问题2

📅  最后修改于: 2021-06-01 03:09:03             🧑  作者: Mango

输出?

#include   
using namespace std;
  
class Base1 {
 public:
     ~Base1()  { cout << " Base1's destructor" << endl; }
};
    
class Base2 {
 public:
     ~Base2()  { cout << " Base2's destructor" << endl; }
};
    
class Derived: public Base1, public Base2 {
   public:
     ~Derived()  { cout << " Derived's destructor" << endl; }
};
    
int main()
{
   Derived d;
   return 0;
}

(一种)

Base1's destructor
Base2's destructor
Derived's destructor

(B)

Derived's destructor
Base2's destructor
Base1's destructor

(C)

Derived's destructor

(D)编译器相关答案: (B)
说明:析构函数总是以相反的顺序调用。
这个问题的测验

想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。