So std is a namespace which allows you isolate your code, which is extremely useful when writing a library. It’s like giving your code an area code (as in for a phone number).
When you write int32 FBullCowGame::GetMaxTries() const { return MyMaxTries; }
that means you are defining a function that belongs to the class FBullCowGame, where int32 is the return type.
Because you would still need to say it belongs to that class otherwise you would just be creating a function outside of that class, you could write this in the header file and would still need to qualify it with FBullCowGame, simplified version of the class in the same file
class FBullCowGame
{
public:
int32 GetMaxTries() const;
private:
int32 MyMaxTries;
};
int32 FBullCowGame::GetMaxTries() const
{
return MyMaxTries;
}
int32 GetMaxTries() const // error const at the end of a non-member function
{
return MyMaxTries; //error MyMaxTries is undefined
}
The instance in where you don’t have to qualify it with the class name is if you are writing it within the class itself
class FBullCowGame
{
public:
int32 GetMaxTries() const { return MyMaxTries; }
private:
int32 MyMaxTries;
};
using
is for type aliases like using int32 = int
which is just saying int32 is the same as if we’re saying int. using namespace x
says to put essentially break the isolation of x
and put it into the global space so you don’t have to qualify it by x::
::
is the scope operator, and says the right hand side belongs to the left hand side i.e. FBullCowGame::GetMaxTries
, GetMaxTries belongs to FBullCowGame
.
is like ::
except the left hand side is an object i.e.
FBullCowGame BCGame; //create an FBullCowGame object called BCGame
BCGame.GetMaxTries(); //call GetMaxTies
That’s to denote the type when declaring/defining something, you don’t use it when you’re just using the function/variable because the type is already defined and adding it would just define a new function/variable
//declare and define a function that takes an int and returns an int
int square(int n) { return n * n; }
int main()
{
int i; // declare variable i
i = square(i); //pass i into square and assign the returned value to i
return 0;
}
Yes. Playing around and tinkering around with your code will also help.