overloading &&, || etc?

Lutger lutger.blijdestijn at gmail.com
Thu Dec 14 03:54:10 PST 2006


inteja wrote:
> Newbie question.
> 
> Say I want to create my own extended bool class that is as easy to use as the
> inbuilt bool (I don't want to simply use an alias or typedef). Below is my
> basic class. With the new opAssign the user of the class can say MyBool myBool
> = true rather than having to explicitly set the property like myBool.value =
> true. Now I want to do the same for && and || operations i.e. I should be able
> to say if (myBool1 && myBool2) just as with the inbuilt bool, but this doesn't
> yet seem possible (and may never be according to the D docs). Does anyone have
> any ideas how I can implement this?

What about: if ( myBool1.and(myBool2).or(myBool3) )?
You can also overload the & and | operators.

But I don't see a case where this would be a good idea.


More information about the Digitalmars-d-learn mailing list