What is the best way to share resources between game states? To the make the game engine flexible, the resources should be able to be loaded on demand and unloaded only when no states no longer need them. This also includes functions that will be shared by the states.
Would it be ugly to have one set of functions, shared_init, shared_cleanup in a base class, and then inherit that class and specify custom init/cleanup functions for resources that only the derived state uses? The shared_init/shared_cleanup functions would then need reference counting in order not to cleanup when there are still states around that use the resources.