In C++
there is a simple method: use the constructor of a global object.
class StartUp
{
public:
StartUp()
{ foo(); }
};
StartUp startup; // A global instance
int main()
{
...
}
This because the global object is constructed before main()
starts. As Lundin pointed out, pay attention to the static initialization order fiasco.