Is there a way to destruct a structure (not a class)?
In C++ a struct
is exactly the same as a class
with the exception of the default visibility on members and bases. So if there is a way to "destruct" a class, you can use the exact same way to "destruct" a structure.
So, if you have a struct s { }
in your C++ program you can do this:
s *v = new s();
delete v; // will call structure's destructor.
Except for the default access specifier ("private" for class, "public" for struct), everything else is same in C++ class and struct. So, YES, you can write and use destructors in struct in the same way that is done in class.
Structs are identical to classes except the default visibility and inheritance are public (rather than private).
So you can create and destroy structs just like this (the same as a class, or built in type):
// Create on the heap, need to manually delete.
MyStruct *const pStruct = new MyStruct();
delete pStruct;
// Created on the stack, automatically deleted for you.
MyStruct struct;
Structs and classes are the same thing, there is just a technical difference (the default field of access) witch dues to a conceptual difference between the two. However every struct like a class call its constructors when the objects have to be created, and its destructor when its visibility field ends.
In C++ structs aren't less powerfull than classes.