Click here to Skip to main content
15,881,092 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The problem here is about we have to write a program using friend function to overload binary &&(logical AND)

What I have tried:

I tried using logic or bt found difficulty using logical and
Posted
Updated 11-Apr-21 0:55am

Quote:
If I'll send solution then why I'm here to ask u question bcz I didn't able to solve
Logical AND is simple:
X && Y is true if and only if A and B are both true. In all other cases it is false.

Overloading it is trivial: Types of Operator Overloading in C++ - GeeksforGeeks[^] just read the article, and learn what it says.
Then read your exact homework question again carefully, and it should be pretty simple to do.

Give it a try - this is the easy stuff!
 
Share this answer
 
Although this is OK as an exercise, overloading operator&& in real code is a bad idea. Say we have this:

if(f() && g()) {...}

The C++ standard says that if f() returns false, g() is not invoked (known as lazy evaluation). However, an overload of operator&& cannot duplicate this behavior. So if g() has side effects, the behavior will differ from what would otherwise have been the case.

It's the same with operator||: if the first expression is true, the second one isn't evaluated.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900