I'm trying to make a Tetris app and describe the number of states each block has.
Here's my code snippet with error included:
const int BLOCK_TYPE_NUM = 6; // number of total block types
int block_states[BLOCK_TYPE_NUM];
block_states[0] = 1; // expected constructor, destructor, or type conversion before '=' token
block_states[1] = 2; // expected constructor, destructor, or type conversion before '=' token
block_states[2] = 2; // expected constructor, destructor, or type conversion before '=' token
block_states[3] = 4; // expected constructor, destructor, or type conversion before '=' token
block_states[4] = 4; // expected constructor, destructor, or type conversion before '=' token
block_states[5] = 4; // expected constructor, destructor, or type conversion before '=' token
So, here's the error for each line containing "block_state" array:
16 ..\Tetris Apps\main.cpp expected constructor, destructor, or type conversion before '=' token
Since you mentioned devC++ I feel compelled to urge you to use something better, their last release was in 2005! Microsoft Visual C++ Express is much better and free.
int block_states[BLOCK_TYPE_NUM] = { 1,2,2,4,4,4 };
but now having a similar error as before with this similar code:
// block.h
// Type Initialization
const int STATES = 4; // number of states
const int BLOCK_COUNT = 4; // number of blocks
const int BLOCK_TYPE_NUM = 6; // number of total block types
int state = 0;
int block_type_num = 0;
int block_states[BLOCK_TYPE_NUM] = { 1,2,2,4,4,4 };
// User Defined Types
struct BLOCK_MESH
{ int x;
int y;
};
struct BLOCK_POS
{ int x;
int y;
};
BLOCK_MESH block[STATES][BLOCK_COUNT][BLOCK_TYPE_NUM];
BLOCK_POS[BLOCK_TYPE_NUM]; // expected unqualified-id before '[' token
Thanks, and here's the error out of code:
34 ..\Tetris Apps\block.h expected unqualified-id before '[' token
You cannot have code outside of functions. (When do they get executed? What about any state it might rely on?)
EDIT:
Looks like this is inside a class, in which case:
// Foobar.h
class Foobar {
private:
static int block_state[BLOCK_TYPE_NUM];
};
...
Since you mentioned devC++ I feel compelled to urge you to use something better, their last release was in 2005! Microsoft Visual C++ Express is much better and free.
@dmatter
Thanks for the advice, I guess I do need to switch to a better compiler, I'm trying to avoid VC++ because I don't like linking in it, also I'm using Allegro 4 to make this game, do you know a tutorial on installing allegro 4 in code::blocks per chance?