Answer to Question #535 in C++ for joanna
How to make the objects of my class to be used in arithmetic expressions together with the objects of standard data types?
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.
No comments. Be first!