Input system reference trouble
Question
I'm using SFML for input system in my application.
size_t WindowHandle;
WindowHandle = ...; // Here I get the handler
sf::Window InputWindow(WindowHandle);
const sf::Input *InputHandle = &InputWindow.GetInput(); // [x] Error
At the last lines I have to get reference for the input system.
Here is declaration of GetInput from documentation:
const Input & sf::Window::GetInput () const
The problem is:
>invalid conversion from ‘const sf::Input*’ to ‘sf::Input*’
What's wrong?
Solution
Is there a special reason why you want to have a pointer rather than a reference? If not, you could try this:
const sf::Input & InputHandle = InputWindow.GetInput();
This will return you a reference to your Input handle.
Btw, this worked for me:
const int& test(int& i)
{
return i;
}
int main()
{
int i = 4;
const int* j = &test(i);
cout << *j << endl;
return 0;
}
Output : 4
Don't know why your compiler doesn't want you to point the reference.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow