c语言 prototype_C语言中的函数调用不明确.候选函数是Prototype和函数本身

本文档是一个关于C++编程的代码片段,展示了作者在斯坦福大学CS106BC课程中遇到的问题,即编译器无法区分函数调用和函数原型。问题出在`humanTurn`函数的调用上,编译器报错'呼叫'humanTurn'是模棱两可的'。代码中包括了创建随机和定制博格游戏板的函数,以及用户交互逻辑。作者寻求帮助以正确调用函数而非函数原型。
摘要由CSDN通过智能技术生成

我正在完成斯坦福CS106B C的任务,我有一个带有任务的“语义问题”.

似乎编译器无法推断调用是函数还是函数的原型.我不明白为什么要对原型进行调用.我怎样才能调用函数而不是原型?我得到它的错误消息“呼叫’人类转动’是模棱两可的”.

错误消息涉及页面底部的humanTurn(Lexicon,Lexicon)函数中的humanTurn(Lexicon,Lexicon)函数的调用.该功能的原型位于主要功能之上.

任何帮助将不胜感激.

亲切的问候,

MEHUL

/*

* File: Boggle.cpp

* ----------------

*/

#include

#include "gboggle.h"

#include "graphics.h"

#include "grid.h"

#include "vector.h"

#include "lexicon.h"

#include "random.h"

#include "simpio.h"

using namespace std;

/* Constants */

const int BOGGLE_WINDOW_WIDTH = 650;

const int BOGGLE_WINDOW_HEIGHT = 350;

const string STANDARD_CUBES[16] = {

"AAEEGN", "ABBJOO", "ACHOPS", "AFFKPS",

"AOOTTW", "CIMOTU", "DEILRX", "DELRVY",

"DISTTY", "EEGHNW", "EEINSU", "EHRTVW",

"EIOSST", "ELRTTY", "HIMNQU", "HLNNRZ"

};

const string BIG_BOGGLE_CUBES[25] = {

"AAAFRS", "AAEEEE", "AAFIRS", "ADENNN", "AEEEEM",

"AEEGMU", "AEGMNN", "AFIRSY", "BJKQXZ", "CCNSTW",

"CEIILT", "CEILPT", "CEIPST", "DDLNOR", "DDHNOT",

"DHHLOR", "DHLNOR", "EIIITT", "EMOTTT", "ENSSSU",

"FIPRSY", "GORRVW", "HIPRRY", "NOOTUW", "OOOTTU"

};

/* Function prototypes */

void welcome();

void giveInstructions();

// Create random board

static Grid randomBoard();

// Create custom board

static Grid customBoard();

static void drawAndFillBoard(Grid);

static void humansTurn(Lexicon,Lexicon);

int main() {

initGraphics(BOGGLE_WINDOW_WIDTH, BOGGLE_WINDOW_HEIGHT);

welcome();

giveInstructions();

string custom = getLine("Type y to create custom board:" );

Grid gridData;

if (custom=="y"){

gridData = customBoard();

} else {

gridData = randomBoard();

}

drawAndFillBoard(gridData);

Lexicon english("EnglishWords.dat");

// Lexicon holds words previously encountered

Lexicon previousWords;

humansTurn(english, previousWords);

return 0;

}

/*

* Function: welcome

* Usage: welcome();

* -----------------

* Print out a cheery welcome message.

*/

void welcome() {

cout << "Welcome! You're about to play an intense game " << endl;

}

/*

* Function: giveInstructions

* Usage: giveInstructions();

* --------------------------

* Print out the instructions for the user.

*/

void giveInstructions() {

cout << endl;

cout << "The boggle board is a grid onto which I ";

cout << "or triple your paltry score." << endl << endl;

cout << "Hit return when you're ready...";

getLine();

}

static Grid randomBoard(){

Vector standardCubes;

for(int i = 0; i<16;i++){

standardCubes.add(STANDARD_CUBES[i]);

}

// Shuffle cubes

for (int i = 0; i < standardCubes.size(); i++) {

int r = randomInteger(i, standardCubes.size()-1);

if (i!=r){

string stringToMove1 = standardCubes.get(i);

string stringToMove2 = standardCubes.get(r);

standardCubes.set(r, stringToMove1);

standardCubes.set(i, stringToMove2);

}

}

// Update grid with random side of cube

Grid gridData(4, 4);

int counter = 0;

for (int columnNo = 0; columnNo <4; columnNo++){

for (int rowNo = 0; rowNo<4; rowNo++) {

string s = standardCubes.get(counter);

int r = randomInteger(0, 5);

gridData[columnNo][rowNo] = s[r];

counter++;

}

}

return gridData;

}

static Grid customBoard(){

Grid gridData(4,4);

string s = getLine("Please enter 16 characters to make up the custom board. Characters will fill the board left to right, top to bottom: ");

for (int i = 0; i < s.length(); i++) {

s[i] = toupper(s[i]);

}

if (s.length()<16){

cout << "String has to be 16 characters long, try again" << endl;

customBoard();

}

int i =0;

for (int columnNo = 0; columnNo <4; columnNo++){

for (int rowNo = 0; rowNo<4; rowNo++) {

gridData[columnNo][rowNo] = s[i];

i++;

}

}

return gridData;

}

static void drawAndFillBoard(Grid gridData){

drawBoard(4, 4);

for (int columnNo = 0; columnNo <4; columnNo++){

for (int rowNo = 0; rowNo<4; rowNo++) {

labelCube(rowNo, columnNo, gridData[rowNo][columnNo]);

}

}

}

static void humansTurn(Lexicon englishWords, Lexicon &previousWords){

/*

Human’s turn (except for finding words on the board). Write the loop that allows the user to enter words. Reject words that have already been entered or that don’t meet the minimum word length or that aren’t in the lexicon. Use the gboggle functions to add words to the graphical display and keep score.

*/

string humanGuess = getLine("Please enter your guess: ");

for (int i = 0; i < humanGuess.length(); i++) {

humanGuess[i] = tolower(humanGuess[i]);

}

if (humanGuess.length()<4){

cout << "Min guess length is four characters" << endl;

humansTurn(englishWords, previousWords);

}

if (!englishWords.contains(humanGuess)) {

cout << "That word is not English, please try another word" << endl;

humansTurn(englishWords, previousWords);

}

if (previousWords.contains(humanGuess)){

cout << "That word has already been guessed, please try another word" << endl;

humansTurn(englishWords, previousWords);

}

// check if word can be made using data on board

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值