I know that whenever an object goes out of scope or deleted compiler automatically calls destructor , but how do I know the scope of an object ?
For e.g. in this code:
#include<iostream>
using namespace std;
class demo
{
static int count;
public:
demo()
{
cout<<"object created"<<++count<<endl;
}
~demo()
{
cout<<"object destroyed"<<count--<<endl;
}
};
int demo::count;
int main()
{
cout<<"in main\n";
demo d1;
{
cout<<"in block 1\n";
demo d2;
{
cout<<"in block 2\n";
demo d3;
}
}
{
cout<<"in block 3\n";
demo d4;
}
cout<<"exit\n";
}
What is the scope of each object?