Pseudo-destructors (C++ only)

A pseudo-destructor is a destructor of a nonclass type.

Read syntax diagramSkip visual syntax diagramPseudo-destructor syntax
   | '-::-'  '-nested_name_specifier-'                                              |
   | '-::-'                                                                         |
     '-::-'  '-nested_name_specifier-'

The following example calls the pseudo destructor for an integer type:

typedef int I;
int main() {
  I x = 10;
  x = 20;

The call to the pseudo destructor, x.I::~I(), has no effect at all. Object x has not been destroyed; the assignment x = 20 is still valid. Because pseudo destructors require the syntax for explicitly calling a destructor for a nonclass type to be valid, you can write code without having to know whether or not a destructor exists for a given type.

Related information