Oct 27, 2012 at 5:10pm UTC
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 Oct 27, 2012 at 5:12pm UTC
Oct 27, 2012 at 5:22pm UTC
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 Oct 27, 2012 at 5:26pm UTC
Oct 27, 2012 at 5:28pm UTC
New?
What's new?How do I use new?
Oct 27, 2012 at 5:33pm UTC
new is how you allocate memory from the heap.