So, on taking the challenge myself the first time - when splitting off GetGuess, I used void rather than string - which, actually worked.
I’m curious as to why we shouldn’t use void when setting up the GetGuess function - what am I missing here?
So, on taking the challenge myself the first time - when splitting off GetGuess, I used void rather than string - which, actually worked.
I’m curious as to why we shouldn’t use void when setting up the GetGuess function - what am I missing here?
returning a string allows you to do this
std::string Guess = GetGuess();
If the function was void you wouldn’t be able to initialise or assign a variable like that.
Ahh, alright - so if I’m understanding correctly:
Forgive me if I’m mixing terminology here - Its been quite a long day.
You give it a return type if you want the function to give back anything to the caller ()
, in this instance we would want to give back the guess so it can then be stored in a variable or passed into another function
int main()
{
ProcessString(GetGuess());
}
void ProcessString(std::string Guess)
{
//does something but doesn't give anything back
}
Thanks Dan!
Came on here to ask the exact same question, thanks for the replies.