TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Sunday 30 August 2020

Assignment Operators Overloading in C++|Assignment Operators Overloading in C++ Example|Assignment Operators Overloading in C++ In Hindi

 Assignment Operators Overloading in C++

Assignment Operator is Used to assign value to an variable. Assignment operator is denoted by equal to sign.  Assignment operator have Two values L-Value and R-value. Operator copies R-Value into L-Value. It is a binary operator.  C++ Overloading assignment operator can be done in object oriented programming. Assignment operator must be overloaded by a non-static member function only. If the overloading function for the assignment operator is not written in the class, the compiler generates the function to overload the assignment operator.

image of Assignment Operators Overloading in C++
Fig:Assignment Operators Overloading in C++

Syntax:

Return_type operator=(const class_name,&)

 

Program:

#include<iostream.h>

#include<conio.h>

class Distance

{

private:

int feet;

int inches;

public:

Distance()

{

feet=0;

inches=0;

}

Distance(int f,int i)

{

feet=f;

inches=i;

 

 }

void operator=(const Distance &D)

{

feet=D.feet;

inches=D.inches;

}

void displayDistance()

{

cout<<”F: “<<feet<< “ I:”<<inches<<endl;

}

};

void main()

{

Distance D1(11,10),  D2(5,11);

cout<<”first distance”;

D1.displayDistance();

cout<<”second distance”;

D2.displayDistance();

D1=D2;

cout<<”first distance”;

D1.displayDistance();

getch();

}


Output:

First Distance: F:11 I: 10

Second Distance: F:5 I:11

First Distance:F:5 I:11

No comments:

Post a Comment