Theese是错误
我在网站上询问我在做哪个课程的答案我得到的答案我要么不明白,要么不够清楚,要么完全糟糕,我一直在寻找2天的解决方案我所做的所有编辑都没有奏效]
无论如何,这是我给出的答案 "在标题中,您尝试多次定义函数。正如你在6号线和15号线以及7号线和18号线上看到的那样。我已经更改了int并且它仍然无效,所以有人可能会更详细地解释或者只是给我正确的代码:
我的代码是
Main.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;
};
Fbullcowgame,的.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:\users\nem\documents\unrealcorse\section_2\section_02\bullcowgame\fbullcowgame.cpp 22
Error C2084 function 'int FBullCowGame::GetMaxTries(void) const' already has a body BullCowGame
c:\users\nem\documents\unrealcorse\section_2\section_02\bullcowgame\fbullcowgame.cpp 18
Error C3867 'FBullCowGame::Reset': non-standard syntax; use '&' to create a pointer to member BullCowGame c:\users\nem\documents\unrealcorse\section_2\section_02\bullcowgame\main.cpp 33
答案 0 :(得分:3)
function'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 :: Reset':非标准语法;使用'&amp;'创建指向成员的指针
尝试调用此方法时错过了()
。这假设您正在尝试引用函数本身,因此与指向成员的指针有关的错误。
BCGame.Reset;