J'ai une classe singleton (s'il vous plaît, ne parlez pas de l'utilisation de singleton).Problèmes de mémoire
class InputSystem : boost::serialization::singleton<InputSystem>
{
private:
boost::shared_ptr<sf::Window> mInputWindow;
public:
InputSystem()
{
mInputWindow = boost::shared_ptr<sf::Window>(new sf::Window(someARgs));
someMethod();
}
void someMethod()
{
mInputWindow->...() // Calling some methods of sf::Window class
// Everything is fine here
}
const sf::Input &Handle() const
{
return mInputWindow.get()->GetInput();
}
};
void main()
{
InputSystem::get_mutable_instance().Handle(); // Here is all members of InputSystem have invalid addresses in memory (0x000)
}
Qu'est-ce qui ne va pas?
Il est impossible de répondre sans la définition 'singleton :: get_mutable_instance()'. – Klaim
Alors, quel est votre modèle de classe 'singleton <>'? (Et comment tout peut-il être correct à 'someMethod()' quand vous ne l'appelez jamais dans l'exemple de code?) Les échantillons incomplets ne font pas de grandes questions. –
@Klaim Ceci est singleton à partir de la sérialisation boost – Ockonal