A destructor for a non-class type, primarily used for calling destructors in templates
In C++, non-class types, such as int
, do not have a destructor. However, the compiler will generate an empty (no-op) psuedo-destructor should such a call be necessary for the implementation of a template or in other cases where the type of a variable may not necessarily be known (e.g. external typedef).
For example, both calls to foo in the following program would be valid:
#include <vector>
template <typename T>
void foo()
{
T x;
// explicitly call destructor
x.~T();
}
int main()
{
foo<int>();
foo< std::vector<int> >();
}
This is true despite the fact that no destructive action will be taken on the int
.