Using FText to Substitute std::string breaks my code and gives me errors when compiling

So I was following along with the Video Lectures and got to Section 2, Number 30. I did the find and replace std::string with FText. I went back and just changed the first one back to std::string like the instructor did in the video. His runs fine. Mine doesn’t. I’m getting like 5 errors. What gives? Please help. Here’s a Screenshot.

Can you post both your header and your cpp? If you’re putting it in the post, make sure to use the code styling.

I put up a pic of the Errors. You need the Header and which cpp, the main.cpp or the FBullCowGame.cpp?

I saw the errors, however I haven’t followed this section closely enough to know what’s wrong directly from them. And then probably the FBullCowGame.cpp file, since that’s the one that throws errors along with its header.

Alright. Got shots of the BullCowGame Header code contents and the FBullCowGame.cpp code contents.

There you go. Hope that helps you help me. :wink: As I said or if I didn’t you can guess, I’m a total noob at this. :smiley:

Also, this is where I undid the first Replace of std::string with FText, just like the instructor did and seems to be giving me the Errors. It’s in the main.cpp file.

So there are a few things that I see wrong with this.

Firstly, you didn’t define the alias FText in your header. Since the header doesn’t include main.cpp (and shouldn’t, for reasons that will become obvious later in the course), you need to also define FText on your header using using FText = std::string. Looking back at the section, it appears Ben used a combination of FString and FText, and that may be confusing, so it’s probably best to stick to one. I haven’t watched the section to see if there is a reason for that.

Secondly, this might be covered in a future lecture, but you need to define a name for the parameter in your CheckGuessValidity function. Currently it’s just a type, which is the first part of the declaration, but that won’t enable you to use the parameter. I see in the repo that he names it Word, so it would be best to follow along there.

If I failed to explain something well enough or if you need more help, feel free to ask.

So where in my Header would I put the line “using FText = std::string” so it would make sense and work properly?

Secondly, in the “CheckGuessValidity” function you said I need to “define a parameter” for it to work. Would I use something like “int” in front of FText where it’s inside of the ( ) braces?

Thanks for taking the time to respond to me. If I can get this working, then I can get back to work on this and get closer to using Unreal to make my dreams come true! XD

I put the using FText = std::string above the class FBullCowGame line and it worked! Thanks.

Not sure about the CheckGuessValidity function. He may get to that later in the video.

Still though, you solved my immediate problem, so thanks a ton!

I wish you all the best in your endeavors.
Keep on being awesome and have a wonderful day!

Anywhere above the class would work fine. You probably want it under the includes, as that’s usually where things like that go.

Second, for the CheckGuessValidity function, it’s actually the opposite of what you think. The FText you have in the function basically is the int, as it’s the parameter type. Now you just need to give the parameter a name.

I believe he covers this later, and I might be infringing a bit on the learning there. So if you don’t fully understand, I wouldn’t sweat it, he gets to it eventually.

Ah and your last reply popped up as I was typing this, so I hope you get your second problem fixed too. Good luck to you as well! If you have anything else come up, I’m here to help.

Privacy & Terms