Pseudo-destructors (C++ only)

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

Read syntax diagramSkip visual syntax diagramPseudo-destructor syntax
 
>>-+-+----+--+-----------------------+--type_name--::--~--type_name-----------------+-><
   | '-::-'  '-nested_name_specifier-'                                              |
   +-+----+--nested_name_specifier--template--template_identifier--::--~--type_name-+
   | '-::-'                                                                         |
   '-+----+--+-----------------------+--~--type_name--------------------------------'
     '-::-'  '-nested_name_specifier-'
 

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

typedef int I;
int main() {
  I x = 10;
  x.I::~I();
  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



[ Top of Page | Previous Page | Next Page | Contents | Index ]