Filipe Sousa wrote:
int main() { { Connection c = ConnectionManager::instance()->connection(); std::clog << "isConnected " << c.isConnected() << std::endl; c.connect();
This initializes the shared_ptr inside c, but has no effect on the shared_ptr in the ConnectionManager map.
std::clog << "isConnected " << c.isConnected() << std::endl;
std::clog << "isConnected " << ConnectionManager::instance()->connection().isConnected() << std::endl;
}
'c' is destroyed here, along with its shared_ptr, which calls mysql_close.
Connection c = ConnectionManager::instance()->connection(); std::clog << "isConnected " << c.isConnected() << std::endl;
return 0; }
You need to .reset( .. ) the shared_ptr in the map, before returning it from the connection manager.