Thread: Problem with a function....scope

  1. #1
    Registered User
    Join Date
    Sep 2003

    Problem with a function....scope

    Ok, I should probably just wait and look at it again tomorrow before posting this because I know I should be able to figure it out. But.......

    I get the error " 'fail' undeclared " It is declared in the extract_fails function and I realize it is out of scope in main() but I can't figure out to get it to work. Shouldn't I be able to reference it somehow. I have posted only the extract_fails() and the relevent portion of main(). If more is needed, I'll post the rest.

    Thanks. I hope my question is clear...I'm getting cross-eyed.

    // include files........
    vector<Student_info> extract_fails(vector<Student_info>& students)
     vector<Student_info> pass, fail;
     vector<Student_info> students;
     for (vector<Student_info>::size_type i = 0;
                       i != students.size(); ++i)
      if (fgrade(students[i]))
     students = pass;
     return fail;
    int main()
     // more code here (students and grades being entered)
     vector<Student_info> fail;  //edit: oops.  not in the code
     for (int i = 0; i != fail.size(); ++i)        //list failing students
         cout << endl << fail[i].name;
    return 0;
    Last edited by MedicKth; 09-22-2003 at 12:43 AM.

  2. #2
    Join Date
    Sep 2003
    Of course you cannot access a local variable from another function. But why don't you just use the return value of your function anyway?

  3. #3
    Registered User
    Join Date
    Sep 2003
    Ok. Feeling stupid but I got it. I knew I should've just put away 'till morning. Thanks for your help though. Just needed a kick in the head.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Problem with function pointers
    By vNvNation in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2004, 06:49 AM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM