SFML community forums

Help => Window => Topic started by: WillYoung on March 22, 2011, 10:50:25 pm

Title: sf::Input& Input; Use within a class.
Post by: WillYoung on March 22, 2011, 10:50:25 pm
Hello everybody!
I want to get the input from the window and the documentation tells me to do this:
Code: [Select]
const sf::Input& Input = App.GetInput();
Which is fine and dandy, it works as expected but I have my project situated in classes. The 'App' window is in a class and I want to have sf::Input within the class also.

The problem is I don't know how to put this into the class and use it in one of the class's functions due to it being a Const and requiring it to get the pointer from App.GetInput(); which I would need to call once the App has been initialized.

Am I missing something fundamental here?
Thanks in advance.
Will,[/code]
Title: sf::Input& Input; Use within a class.
Post by: Nexus on March 22, 2011, 11:05:08 pm
const sf::Input& is a reference, therefore it must be initialized in the constructor's initializer list.
Code: [Select]
class MyClass
{
    public:
        MyClass()
        : app(sf::VideoMode(800, 600), "Title")
        , input(app.GetInput())
        {
        }

    private:
        sf::RenderWindow app;
        const sf::Input& input;
};
Title: sf::Input& Input; Use within a class.
Post by: WillYoung on March 22, 2011, 11:09:00 pm
You Sir require Kudos. Thank you for the quick reply and it has done the job spectacularly, it was something trivial after all!

Will,