Hello, I started the c++ course a few days ago, and in the section 2 in “Clarity is Worth Fighting For” at 8:37 (link here: https://www.gamedev.tv/courses/635496/lectures/11794349), he says that we can store the result of GetGuess() in Guess by doing this:
Guess = GetGuess();
What I don’t understand is how does it works ?
If the function is this:
string GetGuess()
{
string Guessinside = "";
// get a guess from the player
cout << "Enter your guess: ";
getline(cin, Guessinside);
return Guessinside;
}
And the return value is GetGuess, shoudln’t we just write Guess = GetGuess;
? :
void PlayGame()
{
string Guess = "";
Guess = GetGuess;
}
Is it simply that it has been decided that way, or there is a reason of using the ()
?
Second question, if we store GetGuess() in a variable: Guess = GetGuess();
, why is it called at the same time ? Shoudln’t we call the function first and then store it ?
GetGuess();
Guess = GetGuess;
Thanks in advance…