形式参数“板"的重新定义 [英] redefinition of formal parameter 'board'

查看:35
本文介绍了形式参数“板"的重新定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试绘制板时不断收到此错误,因此问题出在 void drawBoard 部分,我不确定如何解决该问题,我尝试不包含矢量板(getBoardSize(),'e');(一个功能)但如果我包括矢量板(boardSize,'e');它会说未识别,也是我第一次尝试使用和理解 uint.

I keep getting this error when I trying to draw a board, so the problem is on the void drawBoard section and I am not sure on how to fix it the issue, I tried to not include vector board(getBoardSize(), 'e'); (a function) but if I include vector board(boardSize, 'e'); it will say unidentified and also this is the first time I trying to use and understand the uint.

#include <Windows.h>
#include <vector>
#include <iostream>

using namespace std;

typedef unsigned int uint;

enum uintType { none, frog, toad };


uint getBoardSize() {
uint value = 0;
// ask for board size
// read value from input
// as long as value if out of bounds (less than 3 or greater than 30), ask for a new value
return value;
}

uint getNumberOfUnits(uint size) {
uint value = 0;
// ask for board size
// read value from input
// as long as value if out of bounds (less than 1 or greater than (size-1/2), ask for a new value
return value;
}

void setup(uint size, uint number, vector<uintType>& board, vector<bool>& visible) {
board.resize(size, none);
visible.resize(size, false);
// add actual units to board
// determine initial visibility
}

void drawBoard(vector<uintType>& board, vector<bool>& visible) {
vector<char> board(getBoardSize(), 'e');
for (int i = 0; i < getBoardSize(); i++) {
    cout << board[i] << " ";
}
cout << endl;
}

// returns true if the player could move, false otherwise
bool handlePlayerTurn() {
// PLACE HOLDER, REPLACE
return true;
}

// returns true if the AI could move, false otherwise
bool handleRandomTurn() {
// PLACE HOLDER, REPLACE
return true;
}

// returns true if the player won, false if the AI won
bool mainLoop(vector<uintType>& board, vector<bool>& visible) {
while (true) {
    // - Draw the board
    drawBoard(board, visible);
    // - Handle player turn
    if (!handlePlayerTurn())
        return false;
    // - Handle AI / random turn
    if (!handleRandomTurn())
        return true;
}
}

void finalMessage(bool playerwon, vector<uintType>& board) {
// Some suitable output
}

int main() {
uint boardSize;
uint numberOfUnits;
vector<uintType> board;
vector<bool> visible;
// - Ask for board size
cout << "Enter the size of the board => ";
cin >> boardSize;
boardSize = getBoardSize();
// - Ask for number of units
numberOfUnits = getNumberOfUnits(boardSize);
// Setup the board:
setup(boardSize, numberOfUnits, board, visible);
// - Run the main loop :
bool playerwon = mainLoop(board, visible);
// - Give win / loss message
finalMessage(playerwon, board);
}

推荐答案

void drawBoard(vector<uintType>& board, vector<bool>& visible) {
    vector<char> board(getBoardSize(), 'e');
    // other stuff
}

您的 board 局部变量与函数的参数 board 同名.为您的局部变量使用不同的名称,然后就设置好了!

Your board local variable has the same name as the parameter board of your function. Use a different name for your local variable and you're set!

这篇关于形式参数“板"的重新定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆