代码中存在多个错误
Multiple Errors In Code
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;
相关文章:
- 为什么此代码存在运行时错误?
- 错误:令牌 { '{' 之前应存在非限定 ID
- 显式 std::exception_ptr 转换为 bool 不存在.VS2010 错误?
- 我正在尝试制作一个自平衡机器人,但编译时存在错误。我不知道如何解决它
- Visual Studio 2019在内置库中存在错误
- C++为什么我的指针选择排序中存在分段错误?
- MSVC 中可能存在的编译器错误
- Microsoft Visual Studio 2019交叉编译CMake库 - 有效,但存在SEG错误
- 在 Windows 10 下使用 GTest 的 CMake - 致命错误 LNK1104:无法打开文件"gtest.lib",但存在调试"gtestd.lib"
- 为什么此代码中存在分段错误?
- 无法在这个基本的Qt代码片段中找到错误,但我被告知它肯定存在?
- 由于相同的文件名/类名存在于不同的SO中而导致的SEG错误
- 以下 OpenCV 源代码中是否存在错误?(#ifdef 没有 #else)
- 带有unique_ptr的通用单链表,MS visual studio C++中存在未知错误
- 指向类成员函数的指针中存在类型转换错误
- 使用c++的gSOAP中的stdsoap2.cpp中存在编译错误
- C++错误:'else'之前应存在非限定 ID
- 这是 GCC 中可能存在的错误吗?
- 我正在调试这个C++程序.编译器不再显示语法错误,但存在隐藏的逻辑错误
- 当错误存在时,为什么我的程序不执行第二个catch块