代码中存在多个错误

Multiple Errors In Code

本文关键字:错误 存在 代码      更新时间:2023-10-16

Theese是错误

我在网站上问我正在做课程的地方,我得到的答案要么不明白,要么不够清楚,要么完全是狗屎,我一直在寻找 2 天的解决方案,并且我所做的所有编辑都没有奏效]

无论如何,这是我得到的答案 "在标题中,您正在尝试多次定义函数。正如您在第 6 行和 15 行以及 7 和 18 行中看到的那样,我已经更改了 int 的周围,但它仍然不起作用,所以有人可以更详细地解释或只是给我正确的代码请:

我的代码是

主.cpp

#include <iostream>
#include <string>
#include "FBullCowGame.h"
void PrintIntro();
std::string GetGuess();
void PlayGame();
bool AskToPlayAgain();
FBullCowGame BCGame; // instantiate a new game
// the entry point for our application
int main() { 
bool bPlayAgain = false;
do {
PrintIntro();
PlayGame();
// TODO add game summary
bPlayAgain = AskToPlayAgain();
} while (bPlayAgain);
return 0;
}
// introduce the game
void PrintIntro() {
constexpr int WORD_LENGTH = 5;
std::cout << "Welme To Bulls and Cows, a fun word game.n";
std::cout << "Can you guess the " << WORD_LENGTH << " letter isogram I'm thinking of? n ";
}
//Play the game
void PlayGame() {
BCGame.Reset;
int MaxTries = BCGame.GetMaxTries(); // checks how many tries the game has got
std::cout << "MaxTries = " << MaxTries << "n";
// loop for the number of turns asking for our guesses 
// TODO make while looop
for (int count = 1; count <= MaxTries; count++) {
std::string Guess = GetGuess(); // TODO check valid guesses
std::cout << "Your guess was " << Guess << "n";
}
return;
}
// get a guess from the player
std::string GetGuess() {
int CurrentTry = BCGame.GetCurrentTry();
std::cout << "Try " << CurrentTry << ". Enter your guess: ";
std::string Guess = "";
std::getline(std::cin, Guess);
return Guess;
}
bool AskToPlayAgain() {
std::cout << "Would you like to play again? (y/n) n ";
std::string Response = "";
std::getline(std::cin, Response);
return (Response[0] == 'y') || (Response[0] == 'Y');
}

页眉

#pragma once
#include<string>
// senpai notice me
class FBullCowGame { 
public:
FBullCowGame(); // contructor
bool Reset(); // make a more rich return valuve
int GetMaxTries()const;
int GetCurrentTry()const;
bool IsGameWon()const;
bool CheckGuessCorrect(std::string); // make a rich return value
// TODO make a method  to get bulls and cowws
//Focus above ,not here
private:
int MyCurrentTry ; // find the contructor or somthing
int MyMaxTries;
};

牛牛游戏,.cpp

#include "FBullCowGame.h"
FBullCowGame::FBullCowGame() {
Reset();
}
int FBullCowGame::GetMaxTries() const { return MyMaxTries;}
int FBullCowGame::GetCurrentTry() const { return MyCurrentTry;}
bool FBullCowGame::Reset() {
constexpr int MyMaxTries = 8;
MyCurrentTry = 1;
return MyMaxTries;
}
int FBullCowGame::GetMaxTries() const {
return;
}
int FBullCowGame::GetCurrentTry() const {
return MyCurrentTry;
}
bool FBullCowGame::IsGameWon() const {
return false;
}
bool FBullCowGame::CheckGuessCorrect(std::string) {
return false;
}

严重性代码说明项目文件行抑制状态

Error C2084 function 'int FBullCowGame::GetCurrentTry(void) const' already has a body BullCowGame 
c:usersnemdocumentsunrealcorsesection_2section_02bullcowgamefbullcowgame.cpp 22 
Error C2084 function 'int FBullCowGame::GetMaxTries(void) const' already has a body BullCowGame 
c:usersnemdocumentsunrealcorsesection_2section_02bullcowgamefbullcowgame.cpp 18 
Error C3867 'FBullCowGame::Reset': non-standard syntax; use '&' to create a pointer to member BullCowGame c:usersnemdocumentsunrealcorsesection_2section_02bullcowgamemain.cpp 33

函数'int FBullCowGame::GetCurrentTry(void) const' 已经有一个主体 BullCowGame

函数int FBullCowGame::GetCurrentTry(void)被定义两次(这意味着第二次看到它时,它已经有一个主体)。

1. int FBullCowGame::GetCurrentTry() const { return MyCurrentTry;}
2. int FBullCowGame::GetCurrentTry() const {
return MyCurrentTry;
}

C2084 函数 'int FBullCowGame::GetMaxTries(void) const' 已经有一个正文 BullCowGame

第二个错误也是如此。

C3867 'FBullCowGame::重置':非标准语法;使用'&'创建指向成员的指针

尝试调用此方法时,您错过了()。这假定您正在尝试引用函数本身,因此会出现与指向成员的指针相关的错误。

BCGame.Reset;