A problem with...references?

Ok, I have on Master class called CAsteroidsApp. It keeps references (not pointers) to other important classes such as CInputManager and CStateManager, here's the code I'm using for this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

namespace Asteroids
{
    class CAsteroidsApp : public Application::CApplication, public Input::CInputMap
    {
        public:
            //...
        private:
            //...

            State::CStateManager    & m_StateManager;
            Input::CInputManager    & m_InputManager;
            Input::CKeyboardManager & m_KeyboardManager;
            Input::CMouseManager    & m_MouseManager;
            sf::RenderWindow        & m_RenderWindow;
    };
}


They are initialised at the .cpp file as it follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

namespace Asteroids
{
    CAsteroidsApp::CAsteroidsApp()
    :
    m_StateManager(Singleton<State::CStateManager>::GetInstance()),
    m_KeyboardManager(Singleton<Input::CKeyboardManager>::GetInstance()),
    m_MouseManager(Singleton<Input::CMouseManager>::GetInstance()),
    m_InputManager(Singleton<Input::CInputManager>::GetInstance()),
    m_RenderWindow(Singleton<sf::RenderWindow>::GetInstance())
    {
        //...
    }
//...
}


After some thinking, I decided that the CKeyboardManager and the CMouseManager, being directly related to input, should be integrated into the CInputManager class, so I did this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
namespace Input
{

    //...

    class CInputManager
    {
        public:
            //...

        private:
            CKeyboardManager & m_KeyboardManager;
            CMouseManager & m_MouseManager;

            //...

    };
}


And I initialised these new references exactly how I did in CAsteroidsApp:
1
2
3
4
5
6
7
8
9
10
11
namespace Input
{
    CInputManager::CInputManager()
    :
    m_KeyboardManager(Singleton<CKeyboardManager>::GetInstance())
    m_MouseManager(Singleton<CMouseManager>::GetInstance())
    {
        //...
    }
//...
}


And now my entire game stopped running. The console shows up and hangs there, doing absolutely nothing. I know these modifications are the problem because I undid all them (leaving CMouseManager and CKeyboardManager references again in CAsteroidsApp) and the game ran fine.

What is causing this and what can I do to fix it?

Best Regards,
~Deimos
What libraries are you using?
Simple And Fast Multimedia Library, only.
I figure you want to take a peek at the singleton class, so here it is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

#ifndef __SINGLETON_H
#define __SINGLETON_H

template<class T>
class Singleton
{
    public:
        static T& GetInstance()
        {
            static T Instance;
            return Instance;
        }
    private:
        Singleton() {}
        virtual ~Singleton() {}
        Singleton(const Singleton&);
        Singleton& operator=(const Singleton&) {}
};

#endif
Last edited on
Topic archived. No new replies allowed.