• Advertisement
Sign in to follow this  

Initialising library

This topic is 2330 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have an Application class, and it uses the PHYSFS library, which requires that the functions PHYSFS_init() and PHYSFS_deinit() be called to set up the library and then clean it up.

In my Application.cpp I simply have this:


class PHYSFS
{
public:
PHYSFS()
{
PHYSFS_init(NULL);
}
~PHYSFS()
{
PHYSFS_deinit();
}
};

PHYSFS physfs;


Is this a good idea?

Share this post


Link to post
Share on other sites
Advertisement
That's fine as long as you can avoid being bitten by the "static initialization order fiasco".

I.e. don't use the same technique for anything that depends on any of the other static constructors also having been run.

Share this post


Link to post
Share on other sites
May be a better idea to have an object that represents the life of your application, and have the PHSYFS instance be a member of it. I tend to have an Application class that is created as a local variable in WinMain and have objects that live for the entire application be members of that.

This makes it very clear and explicit exactly what order things are created and destroyed, and plays nice with exceptions as well.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement