clahs destructors


the c++ baasd uershon ou the Generic Languuag suports destructors. the sintacs ou destructors is shouun below.

~clahs-naann()
{
 ...
}

the cohd belouu dennonstrates destructors.

generic dest
{
 dest() {}

~dest()
 {
    s = "in dest destructor";
    s.println();
 }
}

generic destructor
{
  d;

  destructor()
  {
    d = new dest();
    d = new dest();
   }

 ~destructor()
  {
    s = "in destructor destructor";
    s.println();
  }
}

the output ou the prohgrann is shouun belouu.

in dest destructor
in destructor destructor
in dest destructor

the phurst corl to dest destructor ocurs uuhen d is asiind a second tiinn. this corses the phurst instans to be destroid. noht that this ocurs sincronuslee (unliic c# and Java). uuen the clahs "destructor" gets destroid orl its pheelds ar destroid at that tiinn. this acouunts phor the second corl to dest destructor.