0

so i got some trouble. basically i just want to assign coordinate inputed by player to an array.

here is the code:

void Board::playerInput(int inputX, int inputY, char symbol)
{
    _board[inputX][inputY] = symbol;
}

and here is code where player assign the coordinate:

void manager::askMove()
{
    if (_turn == _player1._playerName){ 
        cout << "insert your x coordinate, " << _player1._playerName << ": ";
        _player1.inputX();
        cout << "insert your y coordinate, " << _player1._playerName << ": ";
        _player1.inputY();
        _board.playerInput(_player1.inputX, _player1.inputY, _player1._playerSymbol);
        _turn = _player2._playerName;
    }
    else {
        cout << "insert your x coordinate, " << _player2._playerName << ": ";
        _player2.inputX();
        cout << "insert your y coordinate, " << _player2._playerName << ": ";
        _player2.inputY();
        _board.playerInput(_player2.inputX, _player2.inputY, _player2._playerSymbol);
        _turn = _player1._playerName;
    }
}

and after i build the code. i got these errors:

Error   2   error C3867: 'Player::inputX': function call missing argument list; use '&Player::inputX' to create a pointer to member c:\users\rlngstrdrgntr\documents\visual studio 2013\projects\project1\project1\manager.cpp  52  1   Project1
Error   3   error C3867: 'Player::inputY': function call missing argument list; use '&Player::inputY' to create a pointer to member c:\users\rlngstrdrgntr\documents\visual studio 2013\projects\project1\project1\manager.cpp  52  1   Project1
Error   4   error C3867: 'Player::inputX': function call missing argument list; use '&Player::inputX' to create a pointer to member c:\users\rlngstrdrgntr\documents\visual studio 2013\projects\project1\project1\manager.cpp  60  1   Project1
Error   5   error C3867: 'Player::inputY': function call missing argument list; use '&Player::inputY' to create a pointer to member c:\users\rlngstrdrgntr\documents\visual studio 2013\projects\project1\project1\manager.cpp  60  1   Project1

i'm not really familiar with these pointers. and i've tried giving & mark like suggested on error report but it just gives me another error. maybe you guys can help me. thank you.

edit:

here is inputX decalration

void Player::inputX()
{
    cin >> _playerInputX;
}

void Player::inputY()
{
    cin >> _playerInputY;
}
GroniumArgor
  • 103
  • 1
  • 11

2 Answers2

2
_player2.inputY();
_board.playerInput(_player2.inputX, _player2.inputY, _player2._playerSymbol);

It looks like your Player class offers the methods inputX() and inputY(), which you are calling in the first line of this snippet. In the second line, you are writing _player2.inputY, like it was a member variable. That's why the compiler complains: It looks like it should be a function call, but the argument list (the ()) is missing.

After reading your edit, it guess that is what you really want to do:

_board.playerInput(_player2.playerInputX, _player2.playerInputY, _player2._playerSymbol);
Horstling
  • 2,131
  • 12
  • 14
  • oh my god.. this... i really feel so stupid now. i assign a method instead of variable. oh my god. thank you so much. thank you. – GroniumArgor Aug 31 '14 at 13:43
0

There are multiple issues with your code.

First something like

class MyClass
{

    public:
        int var;
        void var() { ... }
};

won't compile. Your methods can not have the same name as a member variable. So in your case you could do

class Player
{
        int m_x;
        int m_y;
        ...
    public:
        ...
        int x() const { return m_x; }
        int y() const { return m_y; }
        void inputX();
        void inputY()
};

Secondly you appear to use global variables whose name starts with an underline. These names are reserved for compiler implementers!

Moreover manager::askMove contains a lot of duplicated code and the distribution of the overall functionality appears odd to me.

Community
  • 1
  • 1
mfuchs
  • 2,190
  • 12
  • 20
  • yes i use underline for public variable but i don't know if it's global. it's just before, i used it as private variable and it seems i got confused when i want to access the variable so i just public it. and that askMove is just asking players what coordinate they want to assign. i don't know yet about good distribution in code. so yeah basically i just implement what i know now – GroniumArgor Aug 31 '14 at 13:59