BullCow game, getting "declaration is incompatible" error in VSCode

My GetBullsCows function (right after making it use a struct) now has an error saying it is incompatible with its declaration in the header file. What I have and what was on the screen look identical, but I might just be dumb.

Here is the error:

	"resource": "/i:/Unreal Projects/BullCowGame_starter_kit/Source/BullCowGame/BullCowCartridge.cpp",
	"owner": "C/C++",
	"severity": 8,
	"message": "declaration is incompatible with \"<error-type> UBullCowCartridge::GetBullsCows(const FString &Guess) const\" (declared at line 22 of \"I:\\Unreal Projects\\BullCowGame_starter_kit\\Source\\BullCowGame\\BullCowCartridge.h\")",
	"startLineNumber": 121,
	"startColumn": 34,
	"endLineNumber": 121,
	"endColumn": 46

Here is the function:

FBullCowCount UBullCowCartridge::GetBullsCows(const FString& Guess) const
    FBullCowCount Count;
    for (int32 GuessIndex = 0; GuessIndex < Guess.Len(); GuessIndex++)
        if (Guess[GuessIndex] == HiddenWord[GuessIndex])

        for (int32 HiddenWordIndex = 0; HiddenWordIndex < HiddenWord.Len(); HiddenWordIndex++)
            if (HiddenWord[HiddenWordIndex] == Guess[GuessIndex])
    return Count;

And here is the declaration in the header:

	FBullCowCount GetBullsCows(const FString& Guess) const;

Thanks for any help!

What is line 121?

The function begins on line 121

Screen shot of VSCode where it says the error is

Could you show me the entire header?

Entire header:

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Console/Cartridge.h"
#include "BullCowCartridge.generated.h"

UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class BULLCOWGAME_API UBullCowCartridge : public UCartridge

	virtual void BeginPlay() override;
	virtual void OnInput(const FString& PlayerInput) override;
	void SetupGame();
	void EndGame();
	void CheckGuess(const FString& Guess);
	bool IsIsogram(const FString& Word) const;
	TArray <FString> GetValidWords(const TArray<FString>& WordList) const;
	FBullCowCount GetBullsCows(const FString& Guess) const;

	// Your declarations go below!
	TArray<FString> Isograms;
	FString HiddenWord;
	int32 NumLives;
	FString Guess;
	bool bGameOver;


struct FBullCowCount
	int32 Bulls = 0;
	int32 Cows = 0;

You’ve declared FBullCowCount after you’ve used it on the declaration for GetBullsCows. You can’t use something before you’ve declared it.

Ah, I had moved it down after the UCLASS part cause I get the following error when it is above that section:

That looks fine and should compile.

Ah, it does compile like that. I didnt know there were error messages I could ignore. That’s confusing.
Thank you for your help!

You can’t ignore compilation errors. That is just an error VS Code is detecting i.e. what it thinks it’s an error. Actual errors would come up in the output of compilation.

I had not seen that mentioned in the course. If it is not, I think it should be, as having some errors be meaningful while others are not is very confusing to a beginner who can not check their own code with any confidence.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms