In an application, a resource is any virtual components used by the application, such as texture and sound. Can we clean up a resource with destructor? If can, provide an demonstration example. Thanks.
I try to use destructor to do clean up but the value is still there. Why the object hasn't deleted after calling destructor?
#include <iostream>
using namespace std;
class Demo
{
public:
Demo(); // Constructor prototype
~Demo(); // Destructor prototype
int a;
};
Demo::Demo() // Constructor function definition
{
cout << "An object has just been defined, so the constructor"
<< " is running.\n";
a = 1;
}
Demo::~Demo() // Destructor function definition
{
cout << "Now the destructor is running.\n";
}
int main()
{
cout << "This is displayed before the objects are created.\n";
Demo demoObjA, demoObjB; // Define two Demo objects
cout << demoObjA.a << endl;
cout << "The objects now exist, but are about to be destroyed.\n";
demoObjA.~Demo();
cout << endl;
cout << demoObjA.a << endl;
cin.get();
return 0;
}