![]() |
how to overload unary operator '!' as member funtion
Hi folks,
I am learning operator overloading concept in c++, wrote sample program to test overloading of unary operator '!' and '-'. Code will work if i use them as friend function but not for member function. Can anybody tell where am i going wrong in function bool operator!(const co_ordi &a) and co_ordi operator-(const co_ordi &x); . Is that correct way to declare and define. I am getting following error Error: op_ovld_unary.cc:18: error: ‘bool co_ordi:: operator!(const co_ordi&)’ must take ‘void’ op_ovld_unary.cc: In function ‘int main()’: op_ovld_unary.cc:45: error: no match for ‘operator!’ in ‘!a’ op_ovld_unary.cc:45: note: candidates are: operator!(bool) <built-in> op_ovld_unary.cc:50: error: no match for ‘operator-’ in ‘-b’ op_ovld_unary.cc:22: note: candidates are: co_ordi co_ordi:: operator-(const co_ordi&) Code:
#include<iostream> |
Re: how to overload unary operator '!' as member funtion
I got it.. :)
Code:
bool operator!() |
| All times are GMT +5.5. The time now is 22:04. |