if and array checking

Started by
7 comments, last by rnlf_in_space 11 years, 4 months ago
bool bricks[3][5]={false};

I am trying to check a Boolean array.

the error I am getting is that bricks has to be an lvalue.

if(bricks[2][5]=true)

I know this is very simple, but google is not working very well.
Advertisement
if(bricks[2][5]==true)
thanks a lot
now I get an == error bool * and bool are not compatible.
Can you show actual code, as typed?

It sounds like your array might be declared as bool *bricks[3][5] or you are doing something like if(bricks[2]==true), in which case you are comparing a bool (true) with a pointer to bool.

bool bricks[3][5]={{false,false,false,false,false},{false,false,false,false,false},{false,false,false,false,false}};
void brick_collision()
{
if(bricks[2,4]==true)
{

}


}

here is some of my code
bricks[2,4] isn't how you index a multi-dimensional array in C++.
bricks[2][4], however, is.
cool thanks duh stupid question hehe
To elaborate a bit: bricks[2,4] is still valid C++, take a look at http://en.wikipedia.org/wiki/Comma_operator.

What it actually does is discard the value of 2 and use 4 as the array subscript. As a result, bricks[2,4] evaluates to bricks[4], which is of type bool[5], thus the incompatibility error.

This topic is closed to new replies.

Advertisement