Hi,
I need to create a chessboard with 64 squares.
Is it possible to define an initialize an array with #define?
Code:#define ID_SQUARE[64] for (int i=1; i<65; i++) ID_SQUARE[i]
Hi,
I need to create a chessboard with 64 squares.
Is it possible to define an initialize an array with #define?
Code:#define ID_SQUARE[64] for (int i=1; i<65; i++) ID_SQUARE[i]
Last edited by Ducky; 05-17-2013 at 06:10 AM.
Using Windows 10 with Code Blocks and MingW.
your syntax is a bit off, but you can definitely do things like that. in C++ it's completely unnecessary though, because you have things like std::vector, which can be initialized to a specific size and populate all elements with a particular value. C-style arrays are effectively obsolete.
What can this strange device be?
When I touch it, it gives forth a sound
It's got wires that vibrate and give music
What can this thing be that I found?
No.
How about explain WHAT you're trying to achieve - in english, in the way a chess teacher might explain it to a child, rather than to a programmer - rather than making random guesses about how to achieve it in C++?
Thanks.
These values go in a Win32 function as HMENU parameters and the compiler asking me for a const value so I dont think a C++ vector will do.
Using Windows 10 with Code Blocks and MingW.
What can this strange device be?
When I touch it, it gives forth a sound
It's got wires that vibrate and give music
What can this thing be that I found?
I tried to use a vector and I can initialize it but when I try to use it in WM_COMMAND it wont compile:
error C2051: case expression not constant|
Code:vector<int> ID_SQUARE; for (int i=1; i<65; i++) ID_SQUARE.push_back(i); Later... WM_COMMAND case ID_SQUARE[1] :
Using Windows 10 with Code Blocks and MingW.
What can this strange device be?
When I touch it, it gives forth a sound
It's got wires that vibrate and give music
What can this thing be that I found?
Thanks.
So no other choice but to define 64 values unless I try to use 'if else' statements.
Last edited by Ducky; 05-17-2013 at 09:37 AM.
Using Windows 10 with Code Blocks and MingW.
perhaps we can find a better solution if you explain your problem and what you're trying to do in a little more detail.
What can this strange device be?
When I touch it, it gives forth a sound
It's got wires that vibrate and give music
What can this thing be that I found?
He's stuck with constant values passed to the windows program as messages. He mentions HMENU, but if the squares are laid out on the screen, then he can optionally get messages as the mouse pointer moves through the matrix of squares, and/or get a message if the user clicks on a square, and windows will identify the squares through the resource with constant identifiers.
A program could be used to create the include file(s) for the squares.
Yes thats what Im trying to do and I ended up creating the 64 #defines with a program indeed.
Mouse pointer would be a good idea too thats right but I think creating the chess cases as buttons is easier.
Using Windows 10 with Code Blocks and MingW.
It seems to me that an enumeration fits the bill.Originally Posted by Ducky
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
An enumeration, good idea, thanks.
Using Windows 10 with Code Blocks and MingW.