Overloading Unary Operators Operators which work on a single operand are known as unary operators. Examples are: increment operator(++), decrement operator(–), unary minus operator(-), logical not operator(!) etc. Using a member function to overload an unary operator Following program demonstrates overloading unary minus operator using a member function: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 #include <iostream> using namespace std; class Number { private: int x; public: Number(int x) { this->x = x; } void operator
The post How to overload unary operator in c++ appeared first on Coding Security.
How to overload unary operator in c++
read more
Tidak ada komentar:
Posting Komentar