Using int32 = int; <-- Nt needed in FBullCowGame.cpp

In the video, he added the “using int32 = int;” statement at the top of FBullCowGame.cpp, but it was already declared in the header.

I’m guessing this was an oversight, as he did not include “using FText = std::string;” in the .cpp file. However, perhaps there’s a reason he did it that I’m unaware of…

1 Like

I am pretty sure you are correct. I did not notice the first time I did the course, but the second time I did it, I naturally left it out in the cpp file and everything works just fine.

There is no need to put it there. As we learned by now, the header literally get’s cut and pasted on top of the cpp file :slight_smile:

1 Like

Just wanted to make sure I wasn’t the only one. I paused the video at the instructional page and added my int32 to my header file and all was right with the world.

Yes you are right I also ran into this thoughts today. I was a bit confused why I had to put stuff in every file, because everything worked. So I think the solution in the video should be commented with an explanation why he did it or commitment that this was a fault.

Anyway, great course until yet - nobody’s perfect :slight_smile:

it does compile when removing it from the .cpp since the header is already included, but he specifically said to “explicitly substitute at the top of file, not via include”. I took away that leaving out the “using FString = std::string;” in the FBullCowGame.cpp was actually the oversight. I tried looking both on the MSDN Library & LearnCPP for standards when using aliases via “using”, but I didn’t see anything that sets it one way or the other. Unless he clarifies this point in a later lesson, I think I will err on the side of following the stated instruction instead of assuming it is okay since it works anyways.

Here’s a fun little factoid. Because you’re doing an #include “FBullCowGame” in your main.cpp as well, you really do not need to add the using int32=int; there either. However, it is good practice to explicitly define your aliases used per class either in the class definition or in your header, even if they overlap between classes. It makes the code a lot easier to read when you don’t have to go hunting between all your class headers to find that one alias that makes no sense. It also prevents your aliases from breaking if and when you remove classes from your solution.

I have been going through this portion of the course as a refresher. I have been out of programming for a few years and with a recent layoff, I am planning on going back.

With what I have learned in the past, it is true that you do not need the using keyword in the FBullCowGame.cpp file. That file should only contain the definitions for the FBullCowGame.h declarations. Within the source code, these two files are always paired. Due to what I say in the next paragraph most programmers with access to the source will look in the header file to answer questions as “what is this FString”.

As you become more advanced in coding, you may end up creating libraries for others to use. Within these libraries you will want to hide how you implemented the code. Basically you will hide everything that is in the .cpp file. You will still have to share the header file, so that the other programmers will be able to access the functions you have written. So you should only reveal in the header file the things that are needed to help the programmer use your functions. The using keywords are one of those tools that a programmer will look for.

That is my take anyways…

1 Like

Privacy & Terms