Help___ about bool function

class Iterator
{
private:
Node* position;
List* container;
public:
bool equals(Iterator b) const;
}

bool Iterator::equals(Iterator b) const
{
return position == b.position;
}
// the code is excerpted from
//(Big c++ 2nd Edition ;Chapter 12:list Queues and stacks; P489)
//=======================================================
my question is how could the equals function return a boolean value?
Is "position == b.position" give a boolean value?
Last edited on
(position == b.position) is an expression with the binary operator == used to check for equality of the two operands position and b.position.

Any expression with unary, binary or conditional operators is implicitly evaluated as a boolean. They're commonly called "boolean expressions" for this reason.

Is "position == b.position" give a boolean value?

Essentially, yes. Just like how the following is perfectly valid:

1
2
3
4
5
6
bool a = true;
bool b = false;

bool c = a == b;
//(a == b) is false
//therefore, c is false 
Last edited on
Topic archived. No new replies allowed.