📜  C++ |异常处理问题8

📅  最后修改于: 2021-05-25 20:09:01             🧑  作者: Mango

#include 
using namespace std;
  
class Test {
public:
   Test() { cout << "Constructing an object of Test " << endl; }
  ~Test() { cout << "Destructing an object of Test "  << endl; }
};
  
int main() {
  try {
    Test t1;
    throw 10;
  } catch(int i) {
    cout << "Caught " << i << endl;
  }
}

(一种)

Caught 10

(B)

Constructing an object of Test 
Caught 10

(C)

Constructing an object of Test 
Destructing an object of Test 
Caught 10

(D)编译器错误答案: (C)
说明:在try块内创建对象时,在将控制权转移到catch块之前,将调用该对象的析构函数。
这个问题的测验

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