RAD Studio |  |

abort And Destructors
See Also
Collapse All

If you call abort anywhere in a program, no destructors are called, not even for variables with a global scope.

A destructor can also be invoked explicitly in one of two ways: indirectly through a call to delete, or directly by using the destructor’s fully qualified name. You can use delete to destroy objects that have been allocated using new. Explicit calls to the destructor are necessary only for objects allocated a specific address through calls to new

Copy Code

    #include <stdlib.h>
    class X {
    public:
      .
      .
      .
       ~X(){};
      .
      .
      .
    };
    void* operator new(size_t size, void *ptr)
    {
       return ptr;
    }
    char buffer[sizeof(X)];
    void main()
    {
       X* pointer = new X;
       X* exact_pointer;
       exact_pointer = new(&buffer) X; // pointer initialized at
                                       // address of buffer
    .
    .
    .
       delete pointer;                 // delete used to destroy pointer
       exact_pointer–>X::~X();         // direct call used to deallocate
    }

See Also

Class Initialization

Invoking Destructors

Atexit

Exit And Destructors

Virtual Destructors

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!