Frustrations with const

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Mar 8 12:06:19 PST 2012


On Thu, Mar 08, 2012 at 02:50:50PM -0500, Steven Schveighoffer wrote:
> On Thu, 08 Mar 2012 14:49:12 -0500, H. S. Teoh
> <hsteoh at quickfur.ath.cx> wrote:
> 
> >On Thu, Mar 08, 2012 at 08:22:05PM +0100, Timon Gehr wrote:
[...]
> >>inout(Slot)* findSlot(Key key) inout { ... }
> >
> >Ahhh. Thanks!
> >
> >But that still doesn't solve the problem:
> >
> >	inout(Slot)* findSlot(Key key) inout {
> >		auto slot = slots[hash(key)];
> 
> What is type slot, and how is it constructed?  This snippit isn't
> enough to provide help.
[...]

Slot is a struct, and slots is Slots*[].  But anyway, I found the
problem.  I needed to explicitly declare slot as:

	inout(Slot)* slot = ...

because for whatever reason, auto turns it into inout(Slot*) which
cannot be modified.

I think inout is one of those things that really needs more thorough
treatment for newbies, because coming from a C/C++ background I had no
idea what was wrong. Now that I get it, it makes so much more sense.


T

-- 
Life would be easier if I had the source code. -- YHL


More information about the Digitalmars-d-learn mailing list