Edit: Yeah, look at me typing for minutes while you already solved that stuff all by yourself :)
Anyway you can still read the following for some clarification.
I feel like I would need to make arguments in the parantheses for the overloaded functions. |
Exactly. Overloading means you define the function twice with different types of parameters. Which of the two is going to be executed is decided by the argument passed.
So your speak()s would look like this:
1 2 3
|
void speak(Dog aDog) { // aDog is an arbitrary name to reference the passed dog further in this function
cout << aDog.dogName << " says woof" << endl; // the name of the dog that was passed to this function is printed followed by "says woof"
}
|
Now you do the same for the cat version.
If you then call the speak function in your main, the compiler will decide which function to call, depending on the type of object you passed. For example 'speak(oneDog);' will call the dog version of your function because you instantiated 'oneDog' as an object of the class 'Dog'. The actual names of the variable (=oneDog) and the function paramter (=aDog) are irrelevant. Instead their types are deciding which function is called.
Also what is important in C++: You can only reference objects/variables/classes/etc. that are declared above the point where you want to use them. In this case these overloaded speak() functions need to know the classes Dog and Cat, so they have to be placed below the class declarations. This is where forward declarations/prototypes come in handy.
Something you might want to know for further exercises:
When calling a function like I described here, the function actually creates a copy of the passed object. That means if you change a member of aDog in the speak() function, it won't affect oneDog in the main() function.
This, however is going pretty deep already. You're better off reading a book if you want to know more about that stuff.