ID not declared

Hey all,
I'm getting the error:

53 C:\Dev-Cpp\Company.cpp `ID' has not been declared

and i don't know how to fix it.


in my code
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 "Company.h"
#include "Casual.h"
#include "Manager.h"
#include "StaffMember.h"
#include <vector>
#include <string>
#include <iostream>
#include <fstream>

using namespace std;

Company::Company()
{
      cout << "Would you like to load a file? (Y/N)" << endl;
      char FileLoadChoice;
      cin >> FileLoadChoice;
      vector<StaffMember*> VSM;
      if (FileLoadChoice == 'Y' || 'y')
      {
           string FileName;
           cout << "Enter your filename, including the path and file type." << endl;
           cin >> FileName;
           ifstream in_stream;
           ofstream out_stream;
           in_stream.open("FileName");
           in_stream >> Company::name;
           int ID;
           string WorkType, Name1, Name2;
           double Numeric1, Numeric2;

           while (WorkType != "END")
           {
                 in_stream >> WorkType >> ID >> Name1 >> Name2 >> Numeric1 >> Numeric2;
                 if (WorkType == "Manager" || WorkType == "Casual")
                 {
                    if (WorkType == "Manager")
                    {  
                       VSM.push_back(new Manager(ID, (Name1 + Name2), Numeric1));
                    }
                    if (WorkType == "Casual")
                    {
                       VSM.push_back(new Casual(ID, (Name1 + Name2), Numeric1, Numeric2));
                    }   
                 } 
           }  
      }
      cout << "Payroll for " << Company::name << endl;
      cout << "====================================" << endl;
      cout << "ID     Name      Type       Wage" << endl;
      int i;
      for (i = 0; i= VSM.size(); i++)
      {
          cout << VSM[i].ID << VSM[i].name << VSM[i].WorkType << VSM[i].wage() << endl;
      }    
      
             
}
VSM[i]->ID etc

Line 18 does not work.
Thanks for that.
i'll get right on fixing that bit.
Try to define ID outside of the if statement - if the statement is false, then ID does not exist.
I'm not sure why but often when I have declared something inside of a loop or if/switch statement, it can not be used by other variables. So try defining it before the if statement.
Topic archived. No new replies allowed.