So what's the point of putting the Reset function in the constructor?

Maybe I missed something, but is there a reason why we put the Reset function in the constructor, instead of just calling the function itself?

Thanks, and sorry if it’s a dumb question.

1 Like

Because it’s being used as both construction and Reset. You could have it set out like this

FBullCowGame::FBullCowGame() 
{
    constexpr int MAX_TRIES = 8;
    MyMaxTries = 8;
    MyCurrentTry = 1;
}
void FBullCowGame::Reset()
 {	
    constexpr int MAX_TRIES = 8;
    MyMaxTries = MAX_TRIES;
    MyCurrentTry = 1;
    return;
}

 void PlayGame()
{
    BCGame.Reset();
    //rest of PlayGame
}

Or you could do what Ben did and just call Reset within the construction method.

1 Like

But if you want to put it in the Reset function, why would it need to even go in the Constructor?

Why couldn’t you just have your code like:

  void FBullCowGame::Reset()
{	
constexpr int MAX_TRIES = 8;
MyMaxTries = MAX_TRIES;
MyCurrentTry = 1;
return;
}

void PlayGame()
{
BCGame.Reset();
//rest of PlayGame
}  

Why can’t you just call Reset, like above, without putting the code in the constructor?

I mean you could do that I guess, but it’s just good design to have your variables initialised in a constructor so you’re not limited to having to remember to call a class’ method in order to use the class.

1 Like

Privacy & Terms