   Vectors... I don't get it [SDL Tetris problem]
  I've decided to work with std::vectors instead of arrays in my newest application. I looked at this for some information on them. It all looks pretty straightforward.For some reason, this code doesn't work though:Block blockI( I );std::vector<Block> block;block.push_back( blockI );Block is a class that eats an int in its constructor. I is enumerated to represent an int. Why doesn't this work?blocks.h:94: error: expected constructor, destructor, or type conversion before '.' tokenblocks.h:94: error: expected `,' or `;' before '.' token[Edited by - c4c0d3m0n on February 3, 2008 1:33:04 PM]
Le sigh.   ;  How does it not work? Does it give you a compiler error? A linker error? Runtime problem? Does your computer download the latest Herbert Gruenemeyer tracks to every iPod in a forty mile radius?   ;  I'm sorry for not including the error, I knew I was missing something.. Here it is:blocks.h:94: error: expected constructor, destructor, or type conversion before '.' tokenblocks.h:94: error: expected `,' or `;' before '.' token   ;  Is the third line at file scope? Statements such as this one need to be placed at function scope.   ;  It looks like you're trying to execute a statement outside of a function. That isn't kosher. Also, it looks like you're trying to declare a global variable in a header. That will blow up if you use the header in more than one source file.   ;  *Scratch my delayed post*If the code doesn't happen to be in global space, we would need to see more context then.   ;  Hmmm, I am afraid my entire approach is wrong here... I am programming Tetris, and my basic design is this:There will be a matrix of 10*20 int's, representing either the ID of a block or an empty space.The matrix will be able to update, find full lines, and remove these while having the rest drop down.There will be Tetrominoes, that are just 2 dimensional bool arrays, each true representing one block.The main function will have Tetrominoes running down the field, and checking in the matrix for collisions. Then, after the Tetrominoe is set down, it is added to the matrix, and the matrix updates.My problem is my Block class...enum typesoftetros { I, J, L, O, S, T, Z };class Block{private:    SDL_Color primcolor; // Main    SDL_Color seccolor; // Light edge    SDL_Color bcolor; // Border    SDL_Rect primrect;    SDL_Rect secrect;    SDL_Rect brect;public:    Block( int type )    {   brect.w = block_size;   brect.h = block_size;   secrect.w = block_size - 2;   secrect.h = block_size - 2;   primrect.w = block_size - 4;   primrect.h = block_size - 4;   if( type == I ) {  bcolor = color[redc];  seccolor = color[reda];  primcolor = color[redb];   }   else if( type == J ) {  bcolor = color[whitec];  seccolor = color[whitea];  primcolor = color[whiteb];   }   else if( type == L ) {  bcolor = color[purplec];  seccolor = color[purplea];  primcolor = color[purpleb];   }   else if( type == O ) {  bcolor = color[bluec];  seccolor = color[bluea];  primcolor = color[blueb];   }   else if( type == S ) {  bcolor = color[greenc];  seccolor = color[greena];  primcolor = color[greenb];   }   else if( type == T ) {  bcolor = color[brownc];  seccolor = color[browna];  primcolor = color[brownb];   }   else {  bcolor = color[orangec];  seccolor = color[orangea];  primcolor = color[orangeb];   }    }    void draw( int x, int y, SDL_Surface *surface ) {   brect.x = x;   brect.y = y;   secrect.x = x + 1;   secrect.y = y + 1;   primrect.x = x + 2;   primrect.y = y + 2;   SDL_FillRect( surface, &brect, SDL_MapColor( surface, bcolor ) );   SDL_FillRect( surface, &secrect, SDL_MapColor( surface, seccolor ) );   SDL_FillRect( surface, &primrect, SDL_MapColor( surface, primcolor ) );    }};A block is basicly 3 SDL_Rect's over eachother, at different colourvariations, making them look pretty :)Whenever I want to create an array of Block's, I'm having trouble because of the constructor... I think this whole approach is very wrong, but I don't know how to improve it... Can someone help me please?   ;  You really should mention the errors you are getting in the future.  In this case, I think I know what the problem is.  You say you have trouble creating an array of blocks... well, you don't supply a default constructor so you can't use an array.  Nope, that's it.  The only way around this is to either not use an array (You used std::vector in your initial post, why did you stop?) or to create a default constructor (one with no parameters).Hope that helps.   ;  It should compile fine even without an explicit default constructor. It does on MSVC2008 at least. Without seeing more of the code surrounding where the vector is used, I'd have to side with the not at function scope crowd.