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

Author Topic: Pointer to the Input class  (Read 2183 times)

0 Members and 1 Guest are viewing this topic.

Fsmv

  • Newbie
  • *
  • Posts: 2
    • View Profile
Pointer to the Input class
« on: May 21, 2010, 01:49:47 am »
I have a separate class that needs to access the input data from the main loop. I was trying to use a pointer like I did for the render window but Input won't let me. Sorry I don't know much about pointers. Is reason that the constant is already a pointer and I need to convert it somehow?

My code is:

Code: [Select]
const sf::Input& Input = renderWindow.GetInput();
//*********************************************************
sf::Input &input = Input;   //This same approach worked for
menu.setInput(&input);   //pointing to the renderWindow
//**********************************************************

while(renderWindow.IsOpened()) {
        // Process events
        sf::Event Event;
        while (renderWindow.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                renderWindow.Close();
}

// Fill the background black
renderWindow.Clear(sf::Color(0, 0, 0, 255));

//if menu is not done run the menu loop otherwise start the rest of the program
if(!menu.cleanMenu()){
bool bResult = lgcManager.Loop();
}else{
menu.loop();
}

        // Display window contents on screen
        renderWindow.Display();
}

Where I try to get it I have:
Code: [Select]
void MainMenu::setInput(sf::Input inp){
mpInput = inp;
}


The error I get is:
Code: [Select]
error C2440: 'initializing' : cannot convert from 'const sf::Input' to 'sf::Input &'
1>        Conversion loses qualifiers


I need to know how to point to the input constant so I can get input in other classes.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Pointer to the Input class
« Reply #1 on: May 21, 2010, 08:42:13 am »
Code: [Select]
void MainMenu::setInput(const sf::Input* inp){
   mpInput = inp; // const sf::Input* mpInput
}

menu.setInput(&window.GetInput());
Laurent Gomila - SFML developer

Fsmv

  • Newbie
  • *
  • Posts: 2
    • View Profile
Pointer to the Input class
« Reply #2 on: May 22, 2010, 02:22:32 am »
Thanks problem solved.

 

anything