I realise this question has come up a few times, but I'm trying to get a definitive answer for the above question, but I keep coming across conflicting info. What I need to know is if a basic class object is destructed when I use exit(). I'm aware of dynamic memory needing to be deleted, but I am meaning something more like:
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
class employee
{
public:
employee ();
string name;
~employee();
};
employee::employee ()
{
name = "bob";
}
employee::~employee()
{
cout << "Object destroyed" << endl;
}
int main()
{
employee emp1;
exit(1);
cout << "Hello" << endl;
}
Now if I remove exit(1) from the main, the "Object destroyed" and "Hello" are printed as expected. Leaving it in there though, neither are printed. The reason is obvious for "Hello", but I was under the impression that emp1 would still be destructed, but the destruct message isn't shown...
I was looking at this link and it says about static objects being destroyed. Is the above object not considered static?
If not, is there a way to have a program terminate without it screwing with memory? My project revolves around user input and I was trying to give the option to exit if the user inputs the word 'exit'.
if(input_var == "exit")
{
cout << "You have chosen to exit the program." << endl;
exit(1);
}
Is a rough example of what my intent was.