对于实现了析构函数释放非内存资源的对象来说,这是最常见的问题。
This is mostly a problem with objects that implement a destructor to free non-memory resources.
那些支持析构函数或垃圾收集器的语言通过在C接口上作一层封装有助于降低这个问题发生的概率。
Programming languages that support destructors or have a garbage collector may mitigate this problem by making a wrapper over the C interface.
当句柄范围的析构函数被调用时,所有在那个范围中创建的句柄都将被从栈中移除。
When the handle scope's destructor is called all handles created within that scope are removed from the stack.
换一种说法就是永远都不要为那些其构造函数和析构函数可能抛出异常的类定义全局(静态全局)实例。
The other way to say it is, never define a global (static global) instance of a class whose constructor or destructor may throw exceptions.
对象池接口——有对象意识的接口,在对象创建和删除过程中分别相应地调用构造函数和析构函数。
Object pool interface — an object-aware interface that calls the constructor and destructors appropriately during object creation and deletion, respectively.
队列类的构造函数和析构函数负责创建和销毁互斥锁,见清单1。
The constructor and destructor of the queue class are responsible for the creation and destruction of the mutex, as shown in Listing 1.
如果不使用这两个选项,try和catch代码仍然可以执行,并且系统执行到throw语句时才会调用局部对象的析构函数。
Without either of these options, the try and catch code can still execute, and the system does not call the destructors of local objects up to the throw statement.
wxWidgets 确实是一种功能强大的工具包,但并不是所有人都愿意使用 C++析构函数、内存管理等等。
While wxWidgets is a powerful toolkit, not everybody wants to deal with C++ destructors, memory management, and all the rest.
管理构造函数和析构函数中的异常
因为它没有一个析构函数。
继承层次关系的根类应该定义虚函数性质的析构函数,即使这个析构函数不做任何的事情。
The root class of an inheritance hierarchy should define a virtual destructor even if the destructor has no work to do.
应该忽略析构函数中的异常吗?
是一个析构函数当对象超出作用域称为?
栈展开期间会经常执行析构函数。
允许定义一个析构函数当对像崩溃的时候运行。
Allows defining a destructor function that runs when an object is destroyed.
放在单独的功能调用析构函数和拷贝构造函数和赋值运算符你所需要的功能。
Put the functionality you need in separate functions called by the destructor and the copy constructor and the assignment operator.
析构函数不能有参数,不能有访问级别修饰符,不能被显式调用。实例的析构函数在垃圾收集时自动调用。
Destructors cannot have parameters, they cannot have accessibility modifiers, and they cannot be invoked explicitly. The destructor for an instance is invoked automatically during garbage collection.
为了管理具有指针成员的类,必须定义三个复制控制成员:复制构造函数、赋值操作符和析构函数。
To manage a class with pointer members, we must define all three copy-control members: the copy constructor, assignment operator, and the destructor.
程序员无法控制何时调用析构函数,因为这是由垃圾回收器决定的。
The programmer has no control over when the destructor is called because this is determined by the garbage collector.
与析构函数不同,构造函数内部所做的事情经常会抛出异常。
Unlike destructors, it is often the case that something done inside a constructor might throw an exception.
另外析构函数也不仅仅是用来释放资源。
A destructor is not limited only to relinquishing resources.
另外析构函数也不仅仅是用来释放资源。
A destructor is not limited only to relinquishing resources.
应用推荐