object created in Function accessible by other functions?

I created an array of objects in a function...now is it possible for me to access those objects in a separate function?

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
  void seasonEpAssign()
{
    const int SIZE = 60;
    thronesEp showNumber[SIZE];
    
 
    
    
    
    for(int i = 0; i < SIZE; i++) // Loop to assign season and episode number
        
    {
        if (i <= 9)
        {
            showNumber[i].setSnNo(1);
            showNumber[i].setEpNo(i+1);
            
          
        }
        
        else if (i <= 19)
        {
            
            
            showNumber[i].setSnNo(2);
            showNumber[i].setEpNo(i-9);
           
        }

Last edited on
is it possible for me to access those objects in a separate function?

Not as you have it. showNumber has local scope. It no longer exists when seasonEpAssign exits.

If you want showNumber to be visible across functions, you need to declare it in main and pass it as an argument to functions that need it.

Topic archived. No new replies allowed.