Operators which work on operands are known as a unary operator. Examples are: increment operator(++) decrement operator(–) unary minus operator(-) logical not operator(!) etc. Using a member functions to overload an unary operator Following program demonstrate overloading unary minus operators 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 Numbers { private: int xs; public: Numbers(int xs) { this->xs = xs; } void operator –() { xs =
The post How to overload unary operators in C++ Programming appeared first on Coding Security.
How to overload unary operators in C++ Programming
read more
Tidak ada komentar:
Posting Komentar