本文介绍了Arduino C++ 析构函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道在 Arduino 中你不能使用 delete
.那么C++类中定义的析构函数什么时候被调用?
I know that in Arduino you can't use delete
. So when does the destructor defined in C++ classes gets called?
同样,如果我想创建一个指向数组的指针,我将不得不使用 malloc
和 free
?
Similarly, if I want to create a pointer to array, I would have to use malloc
and free
?
推荐答案
析构函数在对象被销毁时被调用.对于自动(堆栈上)变量,它在离开其作用域 ({}
) 后被调用.阅读有关自动变量的更多信息.
The destructor is called when the object is destroyed. For automatic (on stack) variables, it's called after leaving its scope ({}
). Read more about automatic variables.
这篇关于Arduino C++ 析构函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!