Click here to Skip to main content
15,881,757 members

Response to: Expression must have a constant value

Revision 2
The expression must be constant at compile time. Your code uses a run-time constant. A compile time constant would look like this:
C++
const int x = 5;
Point *Room[x]; // OK here

To create an array at runtime, use the new operator:
C++
Point *Room = new Point[size];
// Use Room here
// ...
// Delete it when finished
delete [] Room;


[EDIT]
Noted that Carlo has edited his solution to use an array of pointers to Point to use the same types as in the question. I will left my example unchanged, because it may be the intention to use this kind of array. If not, Carlo's answer should be used.
[/EDIT]
Posted 13-Feb-13 0:47am by Jochen Arndt.
Tags: