Good morning everyone,
I have a question about classes and header files. In lecture 24 and 25 we create a class and a header file. But I don’t quite understand why we use them. I’m currently in lecture 29 and I thought that it would be more clear. But I still don’t understand it
For example:
In the FBullCowGame header file I have:
public:
int getMaxTries();
private:
int myMaxTries = 5;
In the FBullCowGame class we have the function: GetMaxTries() that returns myMaxTries. In the Main.Cpp file we call that function to get the max tries that the user has.
But why can’t I create a function in the main.cpp file where I get the maxTries?
For example:
int getMaxTries()
{
int maxTries = 5;
return maxTries;
}
And call that function in the playGame() function.
I don’t understand why to make a new class and header file when you get the same result with a function in the main.cpp file.
I hope someone can explain it.
Thanks!