Write a program to overload binary – (minus) operator for Number class using friend function. Number class have
two data members as num1 and num2.
#include <iostream>
using namespace std;
class Number
{
int _num1;
int _num2;
public:
friend Number operator-(const Number &number1, const Number &number2);
};
Number operator+(const Number &number1, const Number &number2)
{
return Number(number1.num1 - number2.num1, number1.num2 - number2.num2);
}
Comments
Leave a comment