G
gorda
Hello,
I have the following code, with a basic class having a constructor and
destructor. in the main section, I create a static pointer to the
class. My question is regarding the destructor. If I dont explicitly
delete the pointer, the destructor is called. However, I expected that
even with out explicitly deleting it, the destructor would be called
when the program ends.
#include <iostream>
using namespace std;
class basic
{
public:
basic()
{ cout << "constructor called" << endl; }
~basic()
{ cout << "destructor" << endl; }
};
int main()
{
static basic *bp = new basic;
//delete bp;
}
Output without the explicit delete call:
constructor
Output with the explicit delete call:
constructor
destructor
Can someone tell me why the destructor is not called when the pointer
is not explicitly deleted?
Thanks,
-Gorda Smith
I have the following code, with a basic class having a constructor and
destructor. in the main section, I create a static pointer to the
class. My question is regarding the destructor. If I dont explicitly
delete the pointer, the destructor is called. However, I expected that
even with out explicitly deleting it, the destructor would be called
when the program ends.
#include <iostream>
using namespace std;
class basic
{
public:
basic()
{ cout << "constructor called" << endl; }
~basic()
{ cout << "destructor" << endl; }
};
int main()
{
static basic *bp = new basic;
//delete bp;
}
Output without the explicit delete call:
constructor
Output with the explicit delete call:
constructor
destructor
Can someone tell me why the destructor is not called when the pointer
is not explicitly deleted?
Thanks,
-Gorda Smith