C++ Program showing assignment operator overloading





The symbol ‘=’ is used as Assignment operators. It is used to assign a value of result for an expression.

This is a sample program showing the overloading of  Assignment operators in c++.

#include<iostream.h>

#include<conio.h>

Class sample

{

Private:

Int x, y;

Public:

Void getdata ()

{

Cout <<” \n enter the value of x and y”;

Cin>> x>>y;

}

Void operator = (sample obj)

{

X= obj.x;

Y= obj.y;

}

Void display ()

{

Cout<<”\n value of x”<<x;

Cout<<”\n value of y”<<y;

}

};

Void main ()

{

Sample obj1, obj2;

Obj1.getdata ();

Obj1.display ();

Obj2=ob1;

Obj2.display();

getch ();

}



Related posts:

  1. Overloading Binary Operator Overloading binary operator An operator requiring two operand is called...
  2. C++ Program showing constructor overloading Constructor is a member function with the same name as...
  3. C++ Program Using Friend Function Friend function is used to access private, public and protected...
  4. C++ Program Using getdata() and display() The program uses member function getdata() and display() in-order to...
  5. Class Template Class Template A class template is a class definition that...