www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - with () doesnt work with struct *s?

reply James Dunne <jdunne4 bradley.edu> writes:
So apparently the with() construct is only for classes?

That's kinda ... yeah.  Minor fix before 1.0 I'd say.

I'd like to use it with structs and struct pointers if at all possible.
It'd sure clean up a lot of my database code here.

1 more thing, toString() in std.string should be renamed since it conflicts with
Object.toString() when you're trying to use it in a class.  referring to it as
std.string.toString(char *) makes it a little cumbersome to use.  Yes, I'm aware
of aliases, and I'll use that to absolve the issue in my own code for now, but I
think it should be given some consideration.

Overall, I still think D is a great language :)  Keep up the great work Walter
and everyone else who's taken the time to share their opinions.

Regards,
James Dunne
Dec 01 2004
parent reply Chris Sauls <Chris_member pathlink.com> writes:
In article <cols64$19jl$1 digitaldaemon.com>, James Dunne says...
So apparently the with() construct is only for classes?

Last time I checked (about two minutes ago) with() works equally well with structs as with classes. I'm betting you've tried something like: # struct S { ... } # S* ptr; # ... # with (ptr) { ... } This will give you an error saying that "with is for Classes, not S*" which is an outdated and misleading error message, as with() /was/ once only for classes but has since been expanded to include structs. So Walter, you need to update that error message. Meanwhile, you can fix your with() statement by changing it to: # with (*ptr) { ... } See that asterisk? You need to dereferance the pointer for with(). I would think it might be automatic, but... its not. -- Chris Sauls
Dec 01 2004
parent James Dunne <jdunne4 bradley.edu> writes:
In article <com4hg$1jki$1 digitaldaemon.com>, Chris Sauls says...
In article <cols64$19jl$1 digitaldaemon.com>, James Dunne says...
So apparently the with() construct is only for classes?

Last time I checked (about two minutes ago) with() works equally well with structs as with classes. I'm betting you've tried something like: # struct S { ... } # S* ptr; # ... # with (ptr) { ... } This will give you an error saying that "with is for Classes, not S*" which is an outdated and misleading error message, as with() /was/ once only for classes but has since been expanded to include structs. So Walter, you need to update that error message. Meanwhile, you can fix your with() statement by changing it to: # with (*ptr) { ... } See that asterisk? You need to dereferance the pointer for with(). I would think it might be automatic, but... its not. -- Chris Sauls

I see what you're saying Chris, and thanks for your reply. Yes the error is slightly misleading and should be changed. However, when the . operator automatically dereferences fields from a struct pointer as well as a normal struct, it should be commonplace to assume that the with () construct should do the same, just in block format. Regards, James Dunne
Dec 05 2004