Page 1 of 1

AND trouble (c++, std::bitset)

Posted: Wed Jun 06, 2007 2:28 pm
by Zacariaz
when doing a conditional &:

Code: Select all

std::bitset<9> a = 7;
std::bitset<9> b = 6;

if(a & b)

or

if(a & b == b) // which is what i really want
i get the following error:
could not convert `std::operator& [with unsigned int _Nb = 9u](((const std::bitset<9u>&)((const std::bitset<9u>*)((+(((unsigned int)p) * 4u)) + ((std::bitset<9u>*)((std::bitset<9u> (*)[2])this))))), ((const std::bitset<9u>&)((const std::bitset<9u>*)((((std::bitset<9u>*)(((unsigned int)i) * 4u)) + ((std::bitset<9u>*)((std::bitset<9u> (*)[8])((C*)this)))) + 8u))))' to `bool'

i understand nothing of this.

Posted: Wed Jun 06, 2007 2:37 pm
by nick8325
& has lower precedence than == :shock:

That is, you must write

Code: Select all

if ((a & b) == b)
instead. The code you wrote parses as

Code: Select all

if (a & (b == b))
This has bitten me before.