Details on my pboblem :
I'm developping a general purpose library that provides helper functons/classes/dialogs for use in other projects. My dialogs in the library are programmed using FOX Toolkit.
Fox Toolkit needs an FXApp object to be constructed before i can create Fox Dialogs.
As i want my lib to be flexible, My dialogs can be opened by a simple function call without needing any prior intialisation code.
But this FXApp object must be created only once for a given process, and it doesn't integrate protection against multiple construction, which results in corruption of some of its static data members at best. It can't be created as a global variable either, because it needs to make sure some other global data has been constructed befor it. That's why it needs to be constructed after main.
I am now constructing it on first use, as a static variable of a function. In this functions, i would like to be able to ckeck if main has already started, in order to prevent it's creation and display an error message in case the end user of the library forgets about this rul and tries to create a dialog before main()
FXApp provides a static method called hasInstance() used to tell if an FXApp is already been created and returniong it's pointer.
If the user has already created a FXApp before using one of my dialogs, hasInstance() allows my lib to use the already created one instead of creating an other
If the end user doesn't use that to check before creating his FXApp, he will of course have problems if he has already used one of my dialogs.
I don't see what main has to do with any of this. What does your code care whether main has run yet or not? Does FOX require that main be started before it can instantiate anything or something?
main can't start if the global variables haven't been constructed. For built-in types this is trivial, but with classes you may have any code in their constructors. You can see for yourself:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
using std::cout;
class A
{
public:
A()
{
cout << "A's constructor\n";
}
};
A a;
int main(int argc, char ** argv)
{
cout << "main started\n";
return 0;
}