Write a program to overload unary (-) operator using
friend function
#include <iostream>
class Invoice
{
public:
Invoice() {};
Invoice(double b, double a, double p)
{
balance = b;
arenda = a;
pays = p;
}
friend void operator-(const Invoice &ip);
double balance{ 0 };
double arenda{ 0 };
double pays{ 0 };
private:
};
void operator-(const Invoice& ip)
{
if (ip.balance < 0)
{
std::cout <<"balance: " << ip.balance << "\n";
}
if (ip.arenda < 0)
{
std::cout << "arenda: " << ip.arenda << "\n";
}
if (ip.pays < 0)
{
std::cout << "pays: " << ip.pays << "\n";
}
}
int main()
{
// A simple example of an overloaded unary operator - displays elements with a negative value
Invoice first(12, -5, 65);
-first;
return 0;
}
Comments
Leave a comment