What does it mean by Overloaded assignment operator... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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............

3rd Jun 2021, 10:24 AM
saurabh
saurabh - avatar
5 Answers
+ 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
3rd Jun 2021, 11:05 AM
Nivya
Nivya - avatar
+ 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/
3rd Jun 2021, 11:45 AM
XXX
XXX - avatar
+ 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?
3rd Jun 2021, 10:48 AM
saurabh
saurabh - avatar
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
3rd Jun 2021, 10:39 AM
Nivya
Nivya - avatar
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.
3rd Jun 2021, 1:33 PM
你知道規則,我也是
你知道規則,我也是 - avatar