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?
1
Expert's answer
2010-08-04T11:11:52-0400
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS