Can anyone teach me about This keyword and Operator Overloading Concepts !! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can anyone teach me about This keyword and Operator Overloading Concepts !!

We continue to develop our Queue management system that we made in the previous module. You are asked to add a new functionality: adding two queues together. The result should be a new queue, where the elements of the first queue come first, followed by the second queue's elements. Given the Queue class, overload the + operator, so that the code in main works and successfully adds two queues. ??? Question of Queue Management 2 in C++ ???

10th Jul 2021, 5:37 AM
Naman Chhabra
Naman Chhabra - avatar
1 Answer
+ 3
You need to overload the + operator, you can do it like this: //Queue class Queue operator+(Queue const &otherObj){//code} //end //main Queue q1,q2,q3; q3 = q1 + q2; //end The operator function will be called from q1 so you can acces q1 as 'this->' and q2 as 'otherObj->' and at the end you need to return a Queue instance
10th Jul 2021, 2:14 PM
Julian Bents
Julian Bents - avatar