Vector of Classes - Scope Issue?

I'm coding a basic student data read/write system. At the moment this won't have any file I/O, so it is pretty basic. I'm having an issue with the structure of the program however. I want to declare a vector of classes so that I can push and remove data at will, and access each class with ease.

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
using namespace std;

bool firstScreen();
void checkInput();
bool uiSelector();
void addData();
void readData();

string uiChoice;
int menuInput;

class studentData {
    string name;
    int SID;
    vector<float> grade;
    int gradeSize; 
    float average;
  public:
    studentData(){SID = 0; gradeSize = 0; average = 0.0F;};
    ~studentData(){}
    void addSID(int iSID){SID = iSID;}
    void pushGrade(float fGrade, studentData *pData){}
    float pullAverage(int student){return average;}
};
int main(int argc, char *argv[]) {
  vector<studentData> students;
  while(firstScreen()) 
  { }
  return EXIT_SUCCESS;
}
bool firstScreen() {
  cout << "Student Data\n\n"
       << "1. Add Data\n"
       << "2. Read Data\n"
       << "3. Exit\n\n>:";
  getline(cin,uiChoice);
  checkInput();
  if(!uiSelector()) { return false; }
}
void checkInput() {
  menuInput = atoi(uiChoice.c_str());
  if((menuInput >3) || (menuInput<1))
   cout << "Input invalid, try again.\n";
}
bool uiSelector() {
  switch(menuInput) {
    case 1: { addData(); }
    case 2: { readData(); }
    case 3: { return false; }
  }
}
void addData() { }
void readData() { }


As you can see, I'm still working out some of the details. But at the moment I'm coming up on an odd problem. How do I access the vector outside of main()? Since I can't declare vector<studentData> globally, is there a way to push_back, read and write the class data in other functions?
Since I can't declare vector<studentData> globally

You can actually.
 is there a way to push_back, read and write the class data in other functions?

Pass vector to functions by reference.
Huh.. I guess you are right! My compiler was being funny for some reason. Thanks for the information! :) I'm sure I'll be back in this thread if anything weird happens with it lol
Topic archived. No new replies allowed.