Click here to Skip to main content
15,885,874 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried many things but didn't know how to fix it.

CSS
int size;
cout<<" Enter The Amount of Rooms : ";
cin >> size;

const int x=size;
Point *Room[x]; //expression must have a constant value;
Posted
Updated 13-Feb-13 0:34am
v2
Comments
Matej Hlatky 13-Feb-13 6:25am    
I think this code won't compile in any version of C#.
missak boyajian 13-Feb-13 6:35am    
Ooops I am working C++. I put c# by mistake.

You cannot do that. You should dynamically allocate memory instead.
C++
Point **Room = new Point*[size]; 


BTW don't forget to delete it then.
 
Share this answer
 
v2
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]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900