I am supposed to observe a rule about scope relating to this code. I really don't understand the point that's trying to be made here, however. The call to Function_Two() from Function_One cases this compiler error:
int Function_Two: expression preceding parentheses of apparent call must have (pointer-to) function type
Is this because there is a conflict between the attempt to 'pass by value' a function and the call at the end of Function_One?
I have been staring at this for a while and have not found any C++ reference that offers something specifically related.
#include <iostream>
usingnamespace std;
void Function_One(int);
void Function_Two();
void Function_Three();
void Function_One(int Function_Two) //surly not the correct way to do this
{
cout<<"You are in Function One"<<endl;
cout<<"Function_One will call Function_Two"<<endl<<endl;
Function_Two(); //this causes a compiler error
}
void Function_Two()
{
cout<<"You are in Function_Two"<<endl;
cout<<"Function_Two will call Function_Three"<<endl<<endl;
Function_Three();
}
void Function_Three()
{
cout<<"You are in Function_Three"<<endl;
cout<<"Function_Three calls no one"<<endl<<endl;
}
int main()
{
Function_Three();
Function_Two();
Function_One(5);
return 0;
}
At line 10, you've rather unwisely named the integer parameter Function_Two. The first thing to do is to choose a more suitable name.
For example, this would be better
void Function_One(int value)
Of course ... if you later tried to do this: value();
the compiler would complain.
In the original code, the parameter name Function_Two caused the same error. I guess the point is that within the scope of Function_One, the function named Function_Two() is hidden, the local variable with the same name takes precedence within that scope.