0

input.cpp Function That Has The Error

void Input::isKeyPressed()
{

    if ( sf::Keyboard::isKeyPressed ( sf::Keyboard::S ) )
    {
        // Here's The Error
        *Input::playerOne.move(0.0 ,  1.0);

    }

}

More Details

This function is the implementation of the class Input and the class has a private variable for a pointer to the sf::RectangleShape in the int main() of the program.

I am trying to access that instantiation of sf::RectangleShape in order to move the object down on the screen. I don't want to create a global variables class just to make this work. I just want to be able to access that method for that specific object.

James Yeoman
  • 605
  • 3
  • 7
  • 17
  • 1
    `(*Input::playerOne).move()` – Kiskae Jun 14 '16 at 11:43
  • 4
    `playerOne->move(0.0 , 1.0);` (And you should consider picking up a [book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list).) – molbdnilo Jun 14 '16 at 11:44
  • @molbdnilo I would pick up a book but I already have a solid understanding of c++. It's just in terms of classes that I need to get better at. I am nearly 17 and live in the UK. In September, I will be starting my second year in college and will be doing a lot of OOP and so I will be improving my skills then. C++ was my first ever used programming language. I self taught myself and absolutely love the language. Even so, I can understand why people don't recommend C++ as a starting language. – James Yeoman Jun 25 '16 at 08:54

1 Answers1

2

You need the pointer to member operator:

Input::playerOne->move(0.0, 1.0);

The explicit scope resolution Input:: is not required, you can rewrite to

playerOne->move(0.0, 1.0);

Bathsheba
  • 231,907
  • 34
  • 361
  • 483