将记录传递给子程序参数C ++

时间:2013-12-06 02:30:56

标签: c++ parameters struct

如何将结构传递给子程序参数? 当我调用checkBelow函数时,它会给我一个错误-'CheckBellow':无法将参数2从'playerInfo'转换为'char' 我之前已经通过过记录数组,但这是我第一次尝试通过一个记录。

  struct playerInfo
{
    char playerName[81];
    char playerID;
};

void CheckBellow ( char board[][10], char playerID, int dropChoice );
int PlayerDrop();
void DisplayBoard ( char board[][10] );

int main()
{
    playerInfo playerOne, playerTwo;
    char board[9][10];
    int trueWidth = 7; 
    int trueLength = 6; 
    int dropChoice;

    cout << "Let's Play Connect 4" << endl << endl;
    cout << "Player One please enter your name: ";
    cin  >> playerOne.playerName;
    playerOne.playerID = 'X';
    cout << "Player Two please enter your name: ";
    cin  >> playerTwo.playerName;
    playerTwo.playerID = 'O';

    DisplayBoard( board );
    dropChoice = PlayerDrop();
    CheckBellow( board, playerTwo, dropChoice );
    DisplayBoard( board );


return 0;
}

void CheckBellow ( char board[][10], playerInfo activePlayer, int dropChoice )
{
    int width = 7;
    int length = 6;

    do
    {
        if ( length == 0 )
        {
            cout << "That row is full, please enter a new row";
            dropChoice = PlayerDrop();
            length = 6;
        }
        if ( board[length][dropChoice] != 'X' && board[length][dropChoice] != 'O' )
            board[length][dropChoice] = activePlayer.playerID;
        else
            --length;
    }while ( board[length][dropChoice] != 'X' && board[length][dropChoice] != 'O' );

}

1 个答案:

答案 0 :(得分:0)

void CheckBellow ( char board[][10], playerInfo activePlayer, int dropChoice )

与声明

不符

void CheckBellow ( char board[][10], char playerID, int dropChoice );

修正声明,即第二个参数char - &gt; playerInfo