May 2012
Intermediate to advanced
679 pages
16h 56m
English
It is possible to overload unary operators. A unary operator operates on only single object. It is logical that such an operator (other than ++ or -- operator) does not modify that object. It should modify a copy2 and return it. Let us study a simple program.
Problem: Write a program to show overloading of unary operator.
Solution: Let us take an example of complex numbers. Many times, we have to find the complex conjugate of this number. Let us overload operator ~ to convert into its complex conjugate. See Program 7.1.
// over1A.cpp #include<iostream.h> class Complex { double x, y ; public: Complex( double a, double b) ; void show() ; Complex ...
Read now
Unlock full access