本文介绍了C ++为全局和类静态变量调用析构函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从我的示例程序,它看起来像在两种情况下调用析构函数。在什么时候它被称为全局和类静态变量的析构函数,因为它们应该被分配在程序堆栈的数据部分?

From my example program, it looks like it does call the destructors in both the cases. At what point does it call the destructors for global and class-static variables since they should be allocated in the data section of the program stack?

推荐答案

从C ++ 03标准的第3.6.3节:

From § 3.6.3 of the C++03 standard:

此外,§9.4.2 7声明:

Furthermore, § 9.4.2 7 states:

但是,如果析构函数没有可观察的行为,调用。 Terry Mahaffey在他的。

However, if a destructor has no observable behavior, it may not be invoked. Terry Mahaffey details this in his answer to "Is a C++ destructor guaranteed not to be called until the end of the block?" .

这篇关于C ++为全局和类静态变量调用析构函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 03:37