Conditional ? bug
Max Samuha
maxter at i.com.ua
Fri Oct 6 04:59:56 PDT 2006
On Fri, 06 Oct 2006 13:51:21 +0200, Tydr Schnubbis <fake at address.dude>
wrote:
>Max Samuha wrote:
>> class Test
>> {
>> int foo()
>> {
>> return 1;
>> }
>> }
>>
>> void main()
>> {
>> Test test = null;
>> int i = test != null ? test.foo() : 0;
>> }
>>
>> This throws access violation exception
>
> From http://www.digitalmars.com/d/expression.html#EqualExpression :
>
>"For class and struct objects, the expression (a == b) is rewritten as
>a.opEquals(b), and (a != b) is rewritten as !a.opEquals(b)."
>
>So you have to use "test != null ? test.foo() : 0" for that kind of
>thing. Just "test ? test.foo() : 0" works too.
Sorry, my fault. I should have used !is or simply test. Thanks
More information about the Digitalmars-d-bugs
mailing list