0

)

While doing the Pset4 task, i got this error in the initBricks function:

error: add: Unrecognized type GObject

This is the corresponding code:

...
#include "gobjects.h"
#include "gwindow.h"
...
// number of rows of bricks
#define ROWS 5

// number of columns of bricks
#define COLS 10
...  
  void initBricks(GWindow window)
    {
        const int brick_height = 10;
        const int brick_width = 38;
        GRect brick[COLS-1][ROWS-1];
        for(int i=0;i<ROWS;i++){
            for(int j=0;j<COLS;j++){ 
                brick[j][i] = newGRect(j*(brick_width+2)+1, i*(brick_height+2)+1, brick_width, brick_height);
                setColor(brick[j][i], "RED");
                setFilled(brick[j][i], true); 
                add(window, brick[j][i]);
            }
        }
    }

This draws two rows and in the third 9 bricks. Then the add-command throws the error. I have no idea what happened here. Maybe a memory/allocation problem? Has somebody any hints? Tanks in advance. Marcus

1 Answer 1

1

I would remove the [j][i] from the brick in setColor, setFilled, and add.
Also I think that your spacing "j*(brick_width+2)+1" does not add up. 10 bricks plus the spaces adds up to more than 400. Unless you changed the size of the window.

1
  • Thanks! I modified the code as you recommended. Now it's working.
    – Marcus
    Commented Dec 29, 2014 at 14:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .