"BullCowCount SubmitGuess(FString);" Won't compile, multiple errors

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

nope. Completely stuck. My code looks identical but wont work?

Hi,

Can you please zip up your project so that we can take a look at all of the code?

Thanks.

https://gist.github.com/anonymous/6b58287cd333acf963019a0411819518 - FBullCowGame.h
https://gist.github.com/anonymous/7c4415c3d59ec6b4319dad10bec2e3e2 - FBullCowGame.cpp
https://gist.github.com/anonymous/c120522113dd833e2f46a1fdd8b0e99b - main.cpp

At this stage I may need to just go back to a working version and redo the lectures.

I have found the error and I expect others may find the same error. The problem is the creation of the class BullCowCount.

The program will not accept BullCowCount BullCowCount;

So instead I’ve gone BullCowCount BBullCowCount;

works.

However now my code only works with BullCowCount(); but not like BullCowCount; as in the video. I still think it’s broken somehow but I’ll see.

1 Like

You need to define the struct (or at least declare it) in the header file. Move your struct definition exactly as it is from the .cpp to the .h file, right before your FBullCowGame class declaration.

Right now, your header file has no clue of what BullCowCount is.

Hope this helps.

2 Likes

Thanks for the reply! That makes a lot more sense now.

Privacy & Terms