Below is an example for my problem. obviously, num is an constant int value. However, when I compile it with Visual Studio 2010, an error happens. The error is
"error c2057 expected constant expression"
The code can be compiled successfully with gcc.
Who know how can solve this problem in Visual Studio?
1 2 3 4 5 6 7 8 9 10
constdouble totalLength = 20.0;
constdouble spacing = 2.0;
constint num = totalLength/spacing;
int main()
{
double panel[num];
return 0;
}
I don't know what code gcc is generating for line 7, because line 7 makes no sense.
The left hand side of the = is fine if you're trying to declare a simple double. On right hand side, it's not clear what you're trying to do. You have a couple of problems.
1) You can't can declare a dimension or subscript (not clear which you intended) to an unnamed variable.
2) You can't assign an (unnamed) array to a simple double (panel).
3) If you're trying to assign an element of an array, then you don't specify the type name, just the array name, however, no array is decalred.