My Header File:
#pragma once
#include<string>
using int32 = int;
using FString = std::string;
class FBullCowGame
{
public:
FBullCowGame(); //constructor
int32 GetMaxTries() const;
int32 GetCurrentTry() const;
bool IsGameWon() const;
void Reset(); //TODO make a more rich return value
bool CheckGuessValidity(std::string); //TODO make a more rich return value
//counts bull & cows and assume gues sis valid
BullCowCount SubmitGuess(FString);
private:
// see constructor for initialization
int32 MyCurrentTry;
int32 MyMaxTries;
FString MyHiddenWord;
};
I declare BullCowCount SubmitGuess(FString); in the header. Then in FBullCowGame.cpp I have:
#include "stdafx.h"
#include "FBullCowGame.h"
using FString = std::string;
using int32 = int;
struct BullCowCount
{
int32 Bulls = 0;
int32 Cows = 0;
};
FBullCowGame::FBullCowGame() {Reset();}
int32 FBullCowGame::GetMaxTries() const { return MyMaxTries; }
int32 FBullCowGame::GetCurrentTry() const { return MyCurrentTry; }
void FBullCowGame::Reset()
{
MyCurrentTry = 1;
constexpr int MAX_TRIES = 8;
MyMaxTries = MAX_TRIES;
return;
}
bool FBullCowGame::IsGameWon() const
{
return false;
}
bool FBullCowGame::CheckGuessValidity(std::string) //TODO create a method for checking valid guesses, if valid continue to next method, if invalid inform the player
{
return false;
}
//recieves a valid guess. increments turn and returns count
BullCowCount FBullCowGame::SubmitGuess(FString)
{
// increment the turn number
MyCurrentTry++;
// setup a return variable
BullCowCount BullCowCount;
//loop through all letters in the guess
// compare letters against the hidden word.
return BullCowCount;
}
// provide a method for counting bulls & cows and incrementing try number
To make it simple here is just the relevant parts:
using int32 = int;
using FString = std::string;
struct BullCowCount
{
int32 Bulls = 0;
int32 Cows = 0;
};
BullCowCount FBullCowGame::SubmitGuess(FString)
{
// increment the turn number
MyCurrentTry++;
// setup a return variable
BullCowCount BullCowCount;
//loop through all letters in the guess
// compare letters against the hidden word.
return BullCowCount;
}
Errors:
Severity Code Description Project File Line Suppression State
Error C2065 ‘MyCurrentTry’: undeclared identifier BullCowGame
Error C2039 ‘SubmitGuess’: is not a member of ‘FBullCowGame’ BullCowGame
Error C3646 ‘SubmitGuess’: unknown override specifier BullCowGame
Error C3646 ‘SubmitGuess’: unknown override specifier BullCowGame
Error C2059 syntax error: ‘(’ BullCowGame
Error C2059 syntax error: ‘(’ BullCowGame
Error C2238 unexpected token(s) preceding ‘;’ BullCowGame
Error C2238 unexpected token(s) preceding ‘;’ BullCowGame