Jump to content

  • Log In with Google      Sign In   
  • Create Account

if and array checking


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 16 December 2012 - 10:46 PM

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.


Sponsor:

#2 JTippetts   Moderators   -  Reputation: 8662

Like
1Likes
Like

Posted 16 December 2012 - 10:50 PM

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

#3 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 16 December 2012 - 10:53 PM

thanks a lot


#4 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 16 December 2012 - 11:00 PM

now I get an == error bool * and bool are not compatible.

#5 JTippetts   Moderators   -  Reputation: 8662

Like
0Likes
Like

Posted 16 December 2012 - 11:04 PM

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.

#6 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 16 December 2012 - 11:08 PM

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


#7 JTippetts   Moderators   -  Reputation: 8662

Like
1Likes
Like

Posted 16 December 2012 - 11:16 PM

bricks[2,4] isn't how you index a multi-dimensional array in C++.
bricks[2][4], however, is.

#8 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 16 December 2012 - 11:28 PM

cool thanks duh stupid question hehe

#9 rnlf   Members   -  Reputation: 1185

Like
2Likes
Like

Posted 17 December 2012 - 02:57 AM

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.

Edited by rnlf, 17 December 2012 - 02:57 AM.

my blog (German)





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS