Site icon T4Tutorials.com

Logical Or operator Overloading C++

How to use the OR Operator in operator overloading in C++.

// overloading the logical opertor - Triangle is Isosceles or not
#include<iostream>
using namespace std;
class T4Tutorials
{
	private :
		int num;
	public :
		void input()
		{
			cin>>num;
		}
		int operator ==(T4Tutorials formal_parameter)
		{
			if(num== formal_parameter.num)
			return 1;
			else
			return 0;
		}	
};
int main()
{
	T4Tutorials object1, object2, object3;
	cout<<"Please  enter side 1 of the triangle.  ";
	object1.input();
	cout<<" Please  enter side 2 of the triangle.";
	object2.input();
	cout<<" Please  enter side 3 of the triangle.";
	object3.input();
	//Here, DONT NEED TO OVERLOAD the or operator explicitly - it works automatically
	if(object1 == object2 || object1 == object3 || object2 == object3 )
	{
	cout<<"The Triangle is Isosceles";
	}
	
	else
	{
	cout<<"The Triangle is not Isosceles.";
	}

 return 0;
}

Output

Please enter side 1 of the triangle. 4

Please enter side 2 of the triangle. 4

Please enter side 3 of the triangle.4

FAQ

Overloading the logical Or operator C++.

How to overload || operator in C++?

How to overload logical operators in C++?

How to overload OR operator in C++?

Overloading the OR operator in C++.

Write a C++ program to overload the OR operator.

Develop a C++ program to overload the || operator.

Write a C++ program to show the results after overloading the  OR || operator.

Overloading the OR operator.

Write a C++ program to show the results after overloading the  OR || operator.

Exit mobile version