Yes. But the problem here is the order of destruction of static object.
I do not quite understand how you would run into issues when
destructing the instance of a singleton. Kindly elaborate.
Static objects are destroyed in the reverse order of construction.
While this may seem perfectly reasonable, sometimes it is not; suppose
for example you have a Server singleton and a Client singleton, where
the latter uses the former. Consider the following scenario:
Client::instance().use_server()
Client::Client()
// now Client constructed
Client::use_server()
Server::instance().serve_client()
Server::Server()
// now Server constructed
Server::serve_client()
Here, Server is constructed after Client, so at program shutdown, Server
is destroyed before Client. Now suppose the destructor of Client tries
to use Server, which doesn't exist any more.
Server::~Server()
// now Server destroyed
Client::~Client()
Server::instance().serve_client() // boom!
The right thing to happen is that Server should outlive Client, whether
Server is created before Client or after Client. One way to ensure that
is to let the Client's constructor use Server at least once, which
ensures that Server is constructed before Client. (And an object is
considered to be constructed when its constructor finishes, without
throwing an exception.)