Bit Array operator overloads

Hello all there is a program that I am writing and it requires me to define these three friend functions.

friend ostream& operator<< (ostream& os, const BitArray& a);
friend bool operator== (const BitArray&, const BitArray&);
friend bool operator!= (const BitArray&, const BitArray&);

I need assistance with this part of the program because I am confused on how I can display the bit array as a continuous sequence of bits withing parenthesis. Also the comparison operators are a bit baffling for me too. If there is anyone that can help that would be great.
What exactly do you mean?
Im not too sure how i should treat the == and != operators is this the same as comparing 2 regular arrays since im using two bit array objects?
I don't know what the implementation of your BitArray is, However, you'd expect to operator== to return true if the two operands are the same, and operator!= to return the opposite.

As I don't know how BitArray is implemented, I can't offer anything helpful. If it's implemented using arrays, as you've indicated, then comparing the arrays and lengths would be the thing to do.
operator != is easy: Implement it with operator==():
1
2
3
bool operator !=(const BitArray &left, const BitArray &right) {
    return !(left == right);
}

Topic archived. No new replies allowed.