Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 too few parameters in the operator function, help please. c++

views
     
Loseeker
post Jul 10 2013, 02:51 PM

Apa Macam
*****
Senior Member
899 posts

Joined: Jul 2008
From: The Land of Smile
QUOTE(Eventless @ Jul 10 2013, 02:16 PM)
http://www.cplusplus.com/doc/tutorial/classes2/
Based on the link above, you can't do that with /. You need to have a parameter when overloading /. You also won't be able to do the following in your code:
CODE
/obj;


I have a feeling that operator overloading was not designed for this purpose. You should be using member functions to do those kind of operations as it will be more readable and most of the values are already inside the object.
*
Eventless is right! You've been using the overloading operator the wrong way. Simply put, the overloading operator should be used to operate on variables contained in 2 different objects of the same type, NOT on the different variables within the same object. That is why the division operator demand an arqument, which for your case, is another object of type NewCalculator.

Try to create an object for both n1 and n2 (example: NewCalculator obj_n1, obj_n2) instead of putting them in the same object (your existing object--> NewCalculator obj). Only then you overload the operator to add/divide/multiply/subtract the two numbers within the two different objects. If you insist on putting the two numbers together within the same object, then you should just create and use member functions to operate the two number instead of operator overloading as Eventless mentioned above.

This post has been edited by Loseeker: Jul 10 2013, 02:57 PM

 

Change to:
| Lo-Fi Version
0.0130sec    0.92    6 queries    GZIP Disabled
Time is now: 16th December 2025 - 04:41 PM