Quick Scope Question

The methods badOp, and createList are outside the scope of main? Well according to my compiler they are.

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
33
34
35
36
37
38
39
  #include <iostream>
#include "LinkedList.h"

using namespace std;

int main()
{
    LinkedList* theList=NULL;
    int op=0;

    cout<<"Welcome user, how can we help you?"<<endl;
    cout<<"(1) Create a blank list.\n(2)Add to existing list\n(3)Remove from existing list.\n(4)Clear existing list\n(5)Change name associated with list\n(6) Print list\n (7) Exit Program\n\n";
    while(badOp(op)){
        cout<<"Please enter a number from 1-7\n";
        cin>>op;
        if(badOp(op))
            cout<<"\nInvalid Entry, please reenter your selection.\n";
    }
    switch(op){
        case 1:
            createList(theList);


    }
}

bool badOp(int op){
    return (op>7 || op<1);
}

void createList(LinkedList* l){
    delete l;
    l=new LinkedList;
    cout<<"\nWhat will you name the new list?\n";
    std::string n;
    cin>>n;
    l->setName(n);
}
badOp and createList needs to have a forward declaration (or to be defined before main())
ah i see. this has been an informative night.
Topic archived. No new replies allowed.