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.
Comments
Leave a comment