I was trying something around default constructor and stumbled upon this kind of situation
static int e = 0;
class X
{
public:
X()
{
e = 10;
}
~X()
{
e = 11;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
if(e == 88) return 88;
X a();
printf("%d", e);
return 0;
}
The output of above code when compiled on visual studio 2010 with default optimisation parameter is 0. Constructor and destructor of X completely gets ignored.
When I change code to
int _tmain(int argc, _TCHAR* argv[])
{
if(e == 88) return 88;
X a = X();
printf("%d", e);
return 0;
}
I get expected output that is 10
I wan't to understand why 1st code doesn't works and 2nd does work?