When i run this code,it gives me segmentation fault.
gdb backtrace result:
Program received signal SIGSEGV, Segmentation fault.
0x08048821 in block::setcolor (this=0x0, c=6) at oopcrack-attack.cpp:21
21 color = c;
(gdb) bt
#0 0x08048821 in block::setcolor (this=0x0, c=6) at oopcrack-attack.cpp:21
#1 0x080489ec in gameboard::gameboard (this=0xbfffef4c, a=0)
at oopcrack-attack.cpp:52
#2 0x08048a96 in main () at oopcrack-attack.cpp:69
(gdb)
#0 0x08048821 in block::setcolor (this=0x0, c=6) at oopcrack-attack.cpp:21
Note that this is 0, which is the cause of your segmentation fault. Now the question is, why did the block have an address of 0?
At lines 43-45 you appear to be allocating 13 rows of 6 blocks each.
However at lines 52 and 62, you've reversed the indexes and are referring to board[x][y] where the row varies from 0-5 and the column varies from 11 down to 4. Not sure if this is what you intended, but it seems you're indexing outsode the rows you allocated.
> At lines 43-45 you appear to be allocating 13 rows of 6 blocks each.
except that no block is created.
you've got a 13x6 grid of pointers to block, that were no initialized.