I think I can help you better understand by using simple data types for a moment. I think you are getting confused by having the same variable names in main as well as the function, I am hoping to better explain scope.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#include <iostream>
void Foo(int x)
{
x = 3;
}
void Foo2(int x)
{
x = x + 3;
cout << x;
}
int main()
{
int bar = 1;
Foo(bar);
cout << bar; //this will output 1
int x = 2;
Foo2(x); //this will call Foo2, then output 5 while in Foo2
cout << x; //this will output 2
}
|
A variable is local to the brackets containing it, and can only be used by the brackets containing it. When you call a function, you create a new variable, even if it has the same name as the variable you pass in, that functions separate. So when I call function Foo(int), it doesn't modify the variable bar that I pass in, because it takes the value of bar, and assigns it to the new variable that is local to Foo(int), x. So when I cout bar, bar is still 1, because Foo(int) didn't modify it. When I am passing in bar, I am not passing in a variable, I am passing in the value of bar, 1. Then Foo(int) takes the value of 1, and assigns it to the variable x.
When I call Foo2(int) it creates a new variable (x) that has the value that is passed in (the value of x, which is 2). Even tho they have the same name, the x declared in main() is local to the brackets of main(), and since the function is outside the brackets of main(), it can't 'see' the x variable declare in main(). This is why you pass in a variable when you call Foo2(int). Once inside Foo2(int), if you modify x, it is only referring to the x that was declared by the parameter list. So when I cout x on line 11 it refers to the x that is local to Foo2(int), which is 5. Then, we Foo2(int) exits, and back in main(), when I cout x, it uses the x that is local to main(), which has the value 2.
Going back to your code with fractions, and to answer your questions:
You are correct in that multiply is the function name, that returns nothing, and takes 2 arguments. Everything in your 4th paragraph is correct.
The fifth paragraph, you have 2 separate sF1 variables, 1 in main, and another in the multiply(Fraction, Fraction) function. sF1.nNumerator is called a member (I believe it could be called a member variable, someone correct me if I'm wrong) of Fraction. Each Fraction has a member called nNumerator of the type int.