Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax for the destructor of a nameless class

Status
Not open for further replies.

xwb

Programmer
Jul 11, 2002
6,828
GB
This is one of those mmm I wonder how you would do that questions. In C++, we can declare nameless classes like
Code:
class
{
public:
    void Create ()
    {
        ...
    }

    void Destroy ()
    {
       ...
    }
} noname;
In a named class, if I want Destroy to be called when the object is deleted, I put it in the destructor (~name). What is the syntax for the destructor in a nameless class? The only thing I can think of is a delete operator.
Code:
   void operator ~()   // doesn't get called

   operator ~()        // produces a syntax error

   ~()                 // produces a syntax error
 
Constructor or destructor declarations must have class names, that's why unnamed classes cannot have user-defined constructors or destructor.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top