Array error

I'm getting this error: no match for operator [ ] in my first function. Could anyone point out how to fix it?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
struct arraylist
{
public:
  bool isempty() { return (length == 0);}
  bool isfull() { return ( length == maxsize);}
  int listsize() { return length;}
  void print()
    {
      int i;
      for ( i=0; i < length; i++)
      {
          cout << list[i];
      }
      cout << endl;
    }

  arraylist() { length = 0, maxsize = 1024, list = new int[maxsize], assert(list!= NULL);}
  ~arraylist() { delete [] list;}

    int *list;
    int length;
    int maxsize;
};




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
int first(process *pcb, arraylist list)
{

    //cout << "FIRST FIT:" << endl;
    //cout << pcb->process_name << " "  << pcb->memory << endl;
   
   if ( list.length >= list.maxsize )
   {
       cout << "Cannot insert into a full list." << endl;
   }

    if (  list.isfull() == true)
    {
        cout << "Error not enough memory will try coalesing.";
    }
    for (int i=0; i < pcb->memory; i++)
    {
        list[i] = 1;       // Here is the error
        list.length++;
    }

    list.print();


    cout << "Please press enter to continue...";
    cin.get();
    cin.get();
    return list.length;
}
I don´t really know if these are silly questions, but...

a) are we seeing all of the code?
b) did you inizialize list as an array? (I can´t find it)
list = new int[maxsize];

changing this line solved it.
Topic archived. No new replies allowed.