Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::Input& Input; Use within a class.  (Read 1075 times)

0 Members and 1 Guest are viewing this topic.

WillYoung

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • http://squaredworld.co.uk
    • Email
sf::Input& Input; Use within a class.
« 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]

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6276
  • Thor Developer
    • View Profile
    • Bromeon
sf::Input& Input; Use within a class.
« Reply #1 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;
};
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

WillYoung

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • http://squaredworld.co.uk
    • Email
sf::Input& Input; Use within a class.
« Reply #2 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,