Normally main() is the first function executed in a C++ program. But there may be certain situations where we have to invoke certain functions (like hardware check) before the main() starts.
To achieve this, call the function to be invoked in the constructor of a global object.
For example, see the following code segment.
class CHardwareChecker
{
public:
CHardwareChecker()
{
CheckHardware(); // Function to be invoked before main() starts
………….
}
};
CHardwareChecker HardwareChecker; // Global object
int main()
{
……….
}