Overloading Operators
You can overload operators in addition to overloading functions. As a matter of fact, the system defined left
shift operator << is also overloaded in C++ when used with cout, the C++ variation of the C language printf
function. There is a similar situation with the right shift operator >> in C++ when used with cin, the C++
variation of the C language scanf function. You can take any operator and overload it. But you want to be
cautious and not overdo it, and also you do not create confusion when you overload an operator. The guiding
principle in this regard is the creation of a code−saving and time−saving facility while maintaining simplicity
and clarity. Operator overloading is especially useful for doing normal arithmetic on nonstandard data types.
You could overload the multiplication symbol to work with complex numbers, for example.
Previous Table of Contents Next
Copyright ©
IDG Books Worldwide, Inc.
C++ Neural Networks and Fuzzy Logic:Preface
Overloading Operators
33
Do'stlaringiz bilan baham: |