main is not the first function - bad idea!
Say I create a global object of a class. The constructor of this class does every thing.
Initializing. Performing operations. Everything needed. And then exit(0)s.
Is it okay? Recommended? or bad? very bad? or hardly matters!
For example:
Code:
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;
class foo
{
public:
foo()
{
cout << "Your name please: ";
string name;
getline(cin, name);
time_t now;
time(&now);
tm* tm = localtime(&now);
string salute = "";
if (tm->tm_hour < 12)
{
salute = "Morning";
}
else if (tm->tm_hour < 15)
{
salute = "Afternoon";
}
else
{
salute = "Evening";
}
cout << endl << "Good " << salute << " " << name << " !" << endl;
exit(0);
}
};
foo foo;
int main()
{
cout << "Eeek killed before entering me!" << endl;
return 0;
}