我知道在大多数情况下,我们不应该显式地调用析构函数。然而,我在C++11标准N3485第13.4.5节的模板参数示例中看到了一个例外。
An explicit destructor call for an object that has a type that is a class template specialization may explicitly specify the template-arguments. Example:
template<class T> struct A { ~A(); }; void f(A<int>* p, A<int>* q) { p->A<int>::~A(); // OK: destructor call q->A<int>::~A<int>(); // OK: destructor call }
在这种情况下,我认为我们可以显式地调用析构函数,请您向我解释一下吗?在这个例子中,这些析构函数调用意味着什么?为什么它们是合理的?
另一个问题:
除了实现placement delete
时,我们还可以在哪些情况下显式地调用析构函数?
谢谢。
编辑:我从C++ FAQ中发现,我们不应该在局部变量上显式调用析构函数。