/*The life cycle of an object*/
#include
#include
class Test
{
public:
Test()
{
cout<<"Constructor invoked"<
}
~Test()
{
cout<<"Destructor invoked"<
}
};
Test obj1;
int main()
{
cout<<"main() begins"<
Test obj2;
{
cout<<"Inner block begins"<
Test obj3;
cout<<"Inner block ends"<
}
cout<<"main() ends"<
getch();
return 0;
}
the output i get is
Constructor invoked
main() begins
Constructor invoked
Inner block begins
Constructor invoked
Inner block ends
Destructor invoked
main() ends
it should have been
Constructor invoked
main() begins
Constructor invoked
Inner block begins
Constructor invoked
Inner block ends
Destructor invoked
main() ends
Destructor invoked
Destructor invoked
plz help(destructor should automatically be initialized isn't it?)
i am using borland c++ builder 5.2 is it a factor??
2006-09-27
16:07:22
·
3 answers
·
asked by
Sakar
1
in
Computers & Internet
➔ Programming & Design