对于实现了析构函数释放非内存资源的对象来说,这是最常见的问题。
This is mostly a problem with objects that implement a destructor to free non-memory resources.
因此,也可以在析构函数中安全地使用断言。
Thus, the assertions can be used safely in destructors, too.
那些支持析构函数或垃圾收集器的语言通过在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.
管理构造函数和析构函数中的异常
因为它没有一个析构函数。
因此,从第一个例子不同,我们需要实现一个析构函数。
So, different from the first example, we need to implement a destructor.
继承层次关系的根类应该定义虚函数性质的析构函数,即使这个析构函数不做任何的事情。
The root class of an inheritance hierarchy should define a virtual destructor even if the destructor has no work to do.
当函数结束的时候,对象的析构函数就会被调用。
When the function end, the constructor of the object will be called.
这是可能的析构函数抛出一个异常。
应该忽略析构函数中的异常吗?
我们还需要添加一个析构函数的类。
是一个析构函数当对象超出作用域称为?
栈展开期间会经常执行析构函数。
允许定义一个析构函数当对像崩溃的时候运行。
Allows defining a destructor function that runs when an object is destroyed.
构造函数和析构函数是面向对象程序设计中的难点。
The construction function and the destruction function are difficult parts in object-oriented programming design.
放在单独的功能调用析构函数和拷贝构造函数和赋值运算符你所需要的功能。
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.
析构函数不能有参数,不能有访问级别修饰符,不能被显式调用。实例的析构函数在垃圾收集时自动调用。
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.
应用推荐