Answer to Question #535 in C++ for joanna

Question #535
How to make the objects of my class to be used in arithmetic expressions together with the objects of standard data types?
Expert's answer
It all depends on which side of the arithmetic operator your object is. If on the left, then overloading of the arithmetic operators will help you. If on the right, then there are two solutions: overloading the arithmetic operators in the form of external function or transformation operators overloading. In the signature of the transformation operators you do not need to specify the return type because it is always the same as the name of the operator. For example Foo::operator long() is called when you try to convert object of class Foo to the type long.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be the first!

Leave a comment

New on Blog