0
What does it mean by Overloaded assignment operator...
Somewhere I was visiting on internet to read about move constructor , I found written that "Assuming that the assignment operator is not oveerloadec" .I searched about it but not satisfied by the results .... So please help me to accumulate it............
5 Respostas
+ 3
Okay,it's just overloading the assignment(=) with an another operator so that we can use the data that is existing already
Example
2 methods
Class a{
m1() {
cout<<"m1";
}
m2(){
cout<<"m2";
}
}
To access we call them like
a.m1(); // m1
a.m2(); //m2
m1=m2 //assignment operator overloading
a.m1() //m2
This is called assignment operator overloading
+ 2
Overloading the assignment operator is just like overloading any other operator (except for some concepts like copy-assignment and move-assignment similar to copy/move-initialization).
See operator overlaoding:
https://www.sololearn.com/learning/1901/
https://en.cppreference.com/w/cpp/language/operators
Overloading assignment operator:
https://www.learncpp.com/cpp-tutorial/overloading-the-assignment-operator/
+ 1
Nivya That's ok with me but i am unable to link it with assignment operator overloading...
How does overloading works with Assignment operator?
0
Overloading means same method but different number of or type of parameter(method signature) in simple.
for example if u hv 2 over loaded methods
m1(int a ,int b){
}
m1(float a,float b) {
}
Like this if u pass a arguments with float values m1(2.4,3.4) ,then 2nd m1 will be called bcz it can hold float values,instead if u pass int values then first m1 method will be executed that is called as overloaded methods.
Hope u got an Idea
0
Operator overloading is just a fancy method, including the assignment operator.
However, what's so special about assignment operator is that the operator is =, which is also used to call copy constructor.
If you overload the assignment operator.
someClass y;
someClass x = y; //calls copy constructor
x = y; //calls assignment operator.
On the other hand, if you don't overload it, both calls in second and third line involves the copy constructor.
Because the assignment operator overloading uses =, it's typically only overloaded when you want to define how your class should copy.