I\'m calling the destructor to deallocate memory but it is not deleting my object. What is the reason behind it?
my code is like this:
class A
{
publ
Destructors were not designed to call them explicitly. Basically it is just another (special) method of class. If you want to Uninitialize your object and then still be able to use it you could make our own method:
class B: public A
{
public:
int b;
B() {cout<<"b"<>x;
return 0;
}
Otherwise B will be deleted when out of scope:
int main()
{
{
B b;
b.b = 100; //OK
}
b.b = 100; //compile time error
int x;
cin>>x;
return 0;
}