what's problem?

Hi,
what's problem of these three line?
These Are Errors:
1
2
3
error C2466: cannot allocate an array of constant size 0
IntelliSense: expression must have a constant value 
  expected constant expression


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;

const int n=10;
class employee
{
int a;
public:
void employeeID();
};
void employee :: employeeID()
{
cout<<"Enter ID Number:";
cin>>a;
}
int main()
{
for (int i=0; i<n; i++)
{
employee myemployee[i];
myemployee[i].employeeID();
}
}

Thank you for your answers
Last edited on
employee myemployee[i];

C++ forbids making an array on the stack where the size is not a constant at compile-time. i is not constant. If you want to do this, you have to do it using new. A better option would be to use a proper C++ container like vector.
Last edited on
New?
What's new?How do I use new?
new is how you allocate memory from the heap.
Topic archived. No new replies allowed.