SFML community forums

Help => General => Topic started by: Makuto on August 22, 2011, 07:22:12 pm

Title: Input class cannot copy App.GetInput()
Post by: Makuto on August 22, 2011, 07:22:12 pm
Hi, I'm having trouble programming my own input class.  Here is the basic code I'm having problems with:
Code: [Select]

class input
{
    sf::RenderWindow *iApp;
    sf::Input Input;


    input(sf::RenderWindow *window)
    {
        iApp=window;
    }
//////THIS FUNCTION MUST BE CALLED EVERY FRAME TO GET NEW //INPUTS
    void refreshInput()
    {
        Input=iApp->GetInput();
    }
    ////////////////////////////////////////////////////////////////
    bool checkKey(sf::Key::Code code)
    {
        return Input.IsKeyDown(code);
    }
    void checkMouse(unsigned int *x, unsigned int *y)
    {
        *x=Input.GetMouseX();
        *y=Input.GetMouseY();
    }
    bool checkMouseKey(sf::Mouse::Button button)
    {
        return Input.IsMouseButtonDown(button);
    }

};


My compiler  (code::blocks gcc) outputs this error:

..\..\..\..\..\..\..\..\SFML-1.6\include\SFML\System\NonCopyable.hpp||In member function `sf::Input& sf::Input::operator=(const sf::Input&)':|
..\..\..\..\..\..\..\..\SFML-1.6\include\SFML\System\NonCopyable.hpp|64|error: `sf::NonCopyable& sf::NonCopyable::operator=(const sf::NonCopyable&)' is private|

C:\Documents and Settings\My Documents\Development\Programming\C++\My Projects\Game Lib Testing\main.cpp|18|error: within this context|
||=== Build finished: 2 errors, 0 warnings ===|

Thanks for the help...
Title: Input class cannot copy App.GetInput()
Post by: easy on August 22, 2011, 07:32:08 pm
Use a reference there:

sf::Input& Input;
Title: Input class cannot copy App.GetInput()
Post by: Makuto on August 22, 2011, 10:44:41 pm
There is still an error:

C:\Documents and Settings\Macoy\My Documents\Development\Programming\C++\My Projects\Game Lib Testing\main.cpp||In constructor `input::input(sf::RenderWindow*)':|
C:\Documents and Settings\Macoy\My Documents\Development\Programming\C++\My Projects\Game Lib Testing\main.cpp|12|error: uninitialized reference member `input::Input'|
..\..\..\..\..\..\..\..\SFML-1.6\include\SFML\System\NonCopyable.hpp||In member function `sf::Input& sf::Input::operator=(const sf::Input&)':|
..\..\..\..\..\..\..\..\SFML-1.6\include\SFML\System\NonCopyable.hpp|64|error: `sf::NonCopyable& sf::NonCopyable::operator=(const sf::NonCopyable&)' is private|
C:\Documents and Settings\Macoy\My Documents\Development\Programming\C++\My Projects\Game Lib Testing\main.cpp|18|error: within this context|
||=== Build finished: 3 errors, 0 warnings ===|
Title: Input class cannot copy App.GetInput()
Post by: Nexus on August 22, 2011, 11:38:09 pm
References are constant. Use the constructor initializer list to initialize them.

But why do you even need a separate sf::Input member? As you already store sf::RenderWindow, you can directly call GetInput().
Title: Input class cannot copy App.GetInput()
Post by: Makuto on August 23, 2011, 04:13:05 am
I don't understand exactly what you're saying... will you just edit my original code from the first code to show me what you mean?  Sorry for the dumbness...
Title: Input class cannot copy App.GetInput()
Post by: CodeCriminal on August 23, 2011, 04:24:18 am
By accessing it directly he means you can just do this:

Code: [Select]
renderWindow.GetInput( ).IsKeyDown( code )

instead of having to store your own external reference to the input object.
Title: Input class cannot copy App.GetInput()
Post by: Nexus on August 23, 2011, 09:53:45 am
Quote from: "makuto"
Sorry for the dumbness...
You're not dumb, you should just take the time to read a C++ book ;)

You probably don't understand my statement because you lack some knowledge about constructor initializer lists or references. They would be explained in a good book (like Accelerated C++, C++ Primer or Thinking in C++), the invested time really pays off!
Title: Input class cannot copy App.GetInput()
Post by: Makuto on August 23, 2011, 07:49:31 pm
Oh thanks CodeCriminal and Nexus.  I'm working on Dietal's C++ How to Program (which is awesome), so I know the basics, but I'm still working on classes, pointers, etc.  I just made my first linked list yesterday :(
The code works great.  Sorry for the waste of time :)