Friend operetor overloading

PHOTO EMBED

Sun Jun 26 2022 07:06:41 GMT+0000 (UTC)

Saved by @Ranjan_kumar #c++

#include <bits/stdc++.h>
using namespace std;

class Complex
{
   public:
    int real;
    int img;
   
   Complex(int r=0,int i=0)
   {
      real=r;
      img=i;
   }
   friend Complex operator+(Complex c1,Complex c2);  //friend 
   void display()                          //operator overloading
   {
      
   }
};
Complex operator+(Complex c1,Complex c2)  //operator overloading
    {
      Complex temp;
      temp.real=c1.real+c2.real;
      temp.img=c1.img+c2.img;
      return temp;
    }
int main()
{
   Complex c1(2,5),c2(3,5),c3;
   
   c3=c1+c2;
   cout<<c3.real<<"+i"<<c3.img<<endl;
	return 0;
}
content_copyCOPY