0

I am trying to read in values from a data file. Everything compiles fine except when it gets to lol.GetNextItem(x); it says the x is undeclared identifier and undefined. I am not really sure how to fix it. I believe I attached the part of the code needed to address this but if the rest is needed, let me know.

class SortedList
{
private:
    int length;
    ItemType values[MAX_ITEMS];
    int currentPos;
public:
    void GetNextItem(ItemType &x);
}

void SortedList:: GetNextItem(ItemType &x)
{
currentPos++;
}

int main()
{   
ifstream bug;
 int i = 0;
int size = 0;
bug.open("num.dat");

float values[10];
while (!bug.eof())
{
    bug >> values[i];
    i++;
    size++;
}
SortedList lol;
lol.GetNextItem(x);
bug.close();
return 0;
}
John
  • 39
  • 9
  • 1
    Is this your whole code? As I see, you have not declared variable `x` in this piece of code, so compilator just complains about it – PepeHands Nov 05 '15 at 21:36
  • and what is this supposed to produce in the end? – Marco Nov 05 '15 at 21:39
  • 2
    To sort out another problem, please have a look at [Why is iostream::eof inside a loop condition considered wrong?](http://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong) – Bo Persson Nov 05 '15 at 21:43

1 Answers1

2

Revise this code:

SortedList lol;
ItemType x; // insert this line
lol.GetNextItem(x);
kcraigie
  • 1,192
  • 5
  • 12