Ok so I am working on a game and I'm in the process of developing my Player class. Anyways, what I have is a keyboard function that is called in my main function to make a shape move.
1 2 3 4 5 6 7 8 9 10 11 12 13
|
void myKeyboardFunction(unsigned char key, int x, int y)
{
switch ( key )
{
case 'd':
pointX += 0.2;
break;
case 'a':
pointX -= 0.2;
break;
...blah blah blah more controls......
}
}
|
to call the function I have this in my main function and it works perfectly.
|
glutKeyboardFunc(myKeyboardFunc);
|
What I want to do is move myKeyboardFunc into my Player class, and this is what I have so far.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
class Player
{
private:
GLfloat pointX;
GLfloat pointY;
public:
void playerControls(unsigned char key, int x, int y);
} Player1, Player2, Player3, Player4;
void Player::playerControls( unsigned char key, int x, int y)
{
switch ( key )
{
case 'd':
pointX +=0.2;
break;
....more keys.......
}
}
|
But when I try to call it, trying to copy my previous method,
|
glutKeyboardFunc(Player1.playerControls);
|
I get an error
|
error C3867: 'Player::playerControls': function call missing argument list; use '&Player::playerControls' to create a pointer to member
|
I've tried messing around with this suggestion but then I get an error saying it can't convert parameters. I would just like to understand why the arguments become a problem when I make the function a member of my class, when the first method I used is so easy. Of course help on how to fix this would be nice.
I know it's probably simple as I'm sort of stepping outside of my boundaries with classes and functions in this project, but I figure I have to learn somehow.