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

Author Topic: Input class cannot copy App.GetInput()  (Read 3482 times)

0 Members and 1 Guest are viewing this topic.

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
Input class cannot copy App.GetInput()
« 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...
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

easy

  • Full Member
  • ***
  • Posts: 146
    • MSN Messenger - easy82.contact@gmail.com
    • View Profile
    • Email
Input class cannot copy App.GetInput()
« Reply #1 on: August 22, 2011, 07:32:08 pm »
Use a reference there:

sf::Input& Input;

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
Input class cannot copy App.GetInput()
« Reply #2 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 ===|
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Input class cannot copy App.GetInput()
« Reply #3 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().
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
Input class cannot copy App.GetInput()
« Reply #4 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...
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

CodeCriminal

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
Input class cannot copy App.GetInput()
« Reply #5 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.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Input class cannot copy App.GetInput()
« Reply #6 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!
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Makuto

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
    • Au 79 Games
    • Email
Input class cannot copy App.GetInput()
« Reply #7 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 :)
Macoy Madson-Au 79 Games
Check out my work at http://augames.f11.us/
Most of my SFML-related code is here: https://github.com/makuto/personal/tree/master/gameDev/resources/base2.0
I try to KIS(S), do you?

 

anything