June 07, 2006
What is the rationale for not allowing the '!' operator to be overloaded?

I ask because I had developed a Bool class but I can't use it in place of 'bool' in cases where the syntax is ...

  if (! mybool ) ...

I can overload the '~' operator but that is not as natural for boolean thinking as that operation is more suited to arithmetical functionality.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocracy!"
7/06/2006 5:05:59 PM
June 07, 2006
Derek Parnell skrev:
> What is the rationale for not allowing the '!' operator to be overloaded?

I guess that for classes, the reason is that !c is defined as
"c is null", i.e. the ! refers to the reference, not the class instance. I.e the same reason as why = can't be overloaded for classes.

For structs, I fail to see any reason not to allow overloading of either ! or =.

> I ask because I had developed a Bool class but I can't use it in place of
> 'bool' in cases where the syntax is ...
> 
>   if (! mybool ) ...
> 
> I can overload the '~' operator but that is not as natural for boolean
> thinking as that operation is more suited to arithmetical functionality.

Matlab uses ~ for boolean negation... But I agree with you.

/Oskar