C++中析构函数的用法是什么?

问题描述 投票:0回答:1

我知道C++中构造函数的用法,但我无法理解对象何时死亡以及为什么有析构函数以及如何调用它。

Class Ratio{
public:
Ratio();
~Ratio();
}
Ratio::Ratio(){
cout << "Object is born";
}
Ratio::~Ratio(){
cout << "Object Dies";
}
c++ oop destructor
1个回答
0
投票

我发现当代码到达关闭作用域时,作用域中的对象就会死亡并且析构函数将被调用。

© www.soinside.com 2019 - 2024. All rights reserved.