www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - opIndex in struct

reply "Bent Rasmussen" <exo bent-rasmussen.info> writes:
dmd test.d
test.d(15): cannot implicitly convert int to test struct test { bit x; bit opIndexAssign(bit v, uint i) { return x = v; } void ex() { this[0] = true; // oops } } The error does not manifest if test is a class. DMD 0.95 XP SP1
Jul 14 2004
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Bent Rasmussen wrote:

 dmd test.d
test.d(15): cannot implicitly convert int to test
There aren't 15 lines in your code. So we have yet another line numbering bug?
 struct test
 {
     bit x;
     bit opIndexAssign(bit v, uint i)
     {
         return x = v;
     }
     void ex()
     {
         this[0] = true; // oops
     }
 }
 
 The error does not manifest if test is a class.
I think it's an issue with this in struct actually. In a struct, this means the address of the current object. Don't ask me why. (*this)[0] = true; should work. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
Jul 15 2004
parent "Bent Rasmussen" <exo bent-rasmussen.info> writes:
 There aren't 15 lines in your code.  So we have yet another line
 numbering bug?
No. I just sliced the relevant piece of the code to make the case shorter, and inserted a comment on the interesting line. I didn't figure this was relevant module test; ... void main { }
 I think it's an issue with this in struct actually.

 In a struct, this means the address of the current object.  Don't ask me
 why.

 (*this)[0] = true;

 should work.
Thanks. Excuse the noise. :-)
Jul 15 2004