I don't understand why we are using this (lecture 27-33)

I first want to excuse myself if my english is bad, it is not my first language, but I will try my best.

The part I am struggling with, is in lecture 33, where Ben decides to use :

 FBullCowCount BullCowCount = BCGame.SubmitGuess(string); 

Now I understand that FBullCowCount is a struct, and what it does, I also understand that we are creating a new ‘variable’ BullCowCount of type FBullCowCount.

Now what I fail to understand is BCGame.SubmitGuess(string); the BCGame part

So BCGame should let me have acces to all functions in the class, but I still dont understand why we are using it?
what exactly is this?
does this have something to do with the class or with the constructor we made?

And lastly, would it be the same if I would write:

FBullCowCount BullCowCount = SubmitGuess(string); 

instead of what’s above?

This is only lecture 20 man… don’t think people here will know what you are talking about.
Hopefully u have also posted this discussion on lecture 27 and onward.

Don’t apologise about your English! This is (presumably) an international setting anyway: it won’t be many people’s first language either…

Right. So it sounds like you are confused with the concept of ‘classes’. You should probably try and research this a little. But ok, let me try and summarise for you.
In fact you said “I understand that FBullCowCount is a struct”, so maybe you know what a struct is? Well, classes and structs are pretty much the same thing. The idea is to package variables and methods (functions) into one neat bundle that provides a convenient thing to manipulate at a higher, more abstract level.

An object (= an instance of a class) is like a box, or a system, in a given state as encoded by its member variables (e.g. BCGame is a FBullCowGame, with a certain hidden word to be guessed, and there has been a certain number of tries, and the player may or may not have already won the game). You then provide other parts of the code that are outside of the class with well defined ways of interacting with that object through public methods (getting the state of the game, updating the state of the game, etc.).

If you’ve used things like std::vector and std::string before: these are classes… They may contain certain underlying information, like what values are in the vector, the size of it, etc. But you don’t get to know the details of how this is done, and you don’t get direct access to all this ‘behind the scenes’ structure: you only are allowed to interact with it through specific methods like myVector.size() or myVector.push_back(x).

So in the same way that size(), in the example I just gave, is a method of the std::vector class, SubmitGuess(guess) is a method of FBullCowGame: you can’t call size() unless you have an vector object to call it on, and similarly it doesn’t make sense to call SubmitGuess(guess) unless you have an instance of the FBullCowGame class…

Let me know if that was enough to help you get to grips with this!

Hy Itizir, thank you for your explanation, this clears up everything for me

1 Like

I don’t understand these statements:

1.FBullCowCount SubmitGuess(FString);

2.FBullCowCount FBullCowGame::SubmitGuess(FString)

  1. looks like the struct has a method called SubmitGuess(FString);

  2. looks like FBullCowGame has a method SubmitGuess(FString) but has type FBullCowCount?

I also noticed the instructor is going extremely fast past this code, and not explaining himself like he was earlier on in the lessons. It’s quite frustrating trying to keep up to him when he is not explaining what he is doing.

You probably need to read this.
So the first ‘FBullCowCount’ in both your examples means the same thing: it’s the return type.
Both examples, in a sense, could really mean the same thing (depending on context)…
What you need to know is that when you implement a class method outside the class declaration, you need to specify the scope of the method. Typically you declare in a header:

class MyClass
    myType MyMethod(); // Declaration!

And then in the implementation file:

// Implementation!
myType MyClass::MyMethod()
    // Do whatever...
    return somethingOfMyType;

Everything is cleared up for me thank you!

Privacy & Terms