C++ help i'm lost?

dealing with Scope of Function practice.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream> 

using namespace std; 

void Function_One() 
{ 
cout << "You are in Function_One." << endl; 
cout << "Function_One called no one." << endl << endl; 
} 

void Function_Two() 
{ 
cout << "You are in Function_Two." << endl; 
cout << "Function_Two will call Function_One." << endl << endl; 
Function_One();	
} 

void Function_Three() 
{ 
cout << "You are in Function_Three." << endl; 
cout << "Function_Three will call Function_Two." << endl << endl; 
Function_Two(); 
} 

int main() 
{ 
Function_Three(); 
Function_Two(); 
Function_One(); 

return 0; 
} 


Q10: Please state a rule about where functions must be declared (i.e. scope) when compared to the location of the function call that you observed in the program in Step 1?


i want to say Global scope but now, i'm confused. I really don't understand what is this question asking me. Can somebody help me break it down
Last edited on
Function must be declared before it is called in a scope visible to the caller.

It does not have to be global scope. Namespace scope, file scope or even block scope cn be used.
For example following is a valid program:
1
2
3
4
5
6
7
8
int main()
{
    void foo(); //Declaration
    foo(); //Call
}

void foo() //Definition
{}
That question doesn't make any sense to me either. The function definitions within your example are in global scope, as you observed.

Their "declarations" (also called "prototypes", "forward declarations", etc...) should be within the same scope, but they do not necessarily have to be within the same compilation unit.

Also, on another note, when was C++Shell added to this site? I really like it! :)
Last edited on
Topic archived. No new replies allowed.