int MyFunction(int x) //There is no x already defined in the current scope, so this is allowed
{
return(x * 2);
}
int x; //x is not defined, so this is allowed
int main()
{
x = 2;
x = MyFunction(x);
}
Now, if you were to do it this way:
1 2 3 4 5
int x; //x is not yet defined so this is allowed
int MyFunc(int x) //ERROR! There is already a variable with the same name defined in this scope
{
return(x * 2); //The compiler cannot tell if you mean the parameter x or the global value x
}
You don't need to change the parameter name at all! Your global value x is defined after the include, so it is fine. You don't need to change it at all.
There is obviously some confusion here between declaring and defining types and objects.
Declaring a type tells the compiler that a certain type is available. The compiler can only do so much with the declaration. If it needs to actually use the type it needs to see its definition:
1 2 3 4 5 6
class MyType; // declaration of type MyType
// definition of type MyType
class MyType
{
};
The compiler has to have seen the whole definition of the type before it can use any of its members.
Built in types like int and float are automatically declared and defined. The programmer does not need to do it.
Then there is declaring and defining actual objects. To declare or define an object the compiler needs to have seen the definition of its type. So to declare or define an object of type MyType the compiler must first have seen the class definition above:
1 2 3
extern MyType mt; // declare object of type MyType
MyType mt; // define object of type MyType.
It is the object definition that actually sets aside memory for the object. There should be only one definition for each object. An object declaration simply says that there is an object of that type with that name elsewhere.