Overloading '!'

Oskar Linde oskar.lindeREM at OVEgmail.com
Wed Jun 7 01:14:53 PDT 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




More information about the Digitalmars-d mailing list