Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
July 08, 2003 this * for struct methods versus inout this | ||||
---|---|---|---|---|
| ||||
When in a struct method, the "this" is a pointer to the struct. It'd be better for language leveraging, some clumsy syntax with operator overloading, and consistent syntax if "this" were an inout reference instead. |
July 08, 2003 Re: this * for struct methods versus inout this | ||||
---|---|---|---|---|
| ||||
Posted in reply to Burton Radons | Why would you ever want a class method to be able to change its 'this' pointer? C++ makes this const for a good reason. Sean "Burton Radons" <loth@users.sourceforge.net> wrote in message news:bedj00$20vt$1@digitaldaemon.com... > When in a struct method, the "this" is a pointer to the struct. It'd be better for language leveraging, some clumsy syntax with operator overloading, and consistent syntax if "this" were an inout reference instead. |
July 08, 2003 Re: this * for struct methods versus inout this | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | Sean L. Palmer wrote:
> Why would you ever want a class method to be able to change its 'this'
> pointer? C++ makes this const for a good reason.
I'm not talking about "this" in class, only about struct. This is currently how it's done:
struct vec3
{
vec3 mulass (vec3 other)
{
return *this = *this * other;
}
}
Pointers can be more than one cell in length, can be null, and can be re-assigned. "this" in struct is invalid on all counts:
void foo ()
{
vec3 bar;
if (this === null) /* Never true */
this [1]; /* Invalid */
this = &bar; /* Invalid */
}
|
July 10, 2003 Re: this * for struct methods versus inout this | ||||
---|---|---|---|---|
| ||||
Posted in reply to Burton Radons | You're saying it should be a reference instead of a pointer. I agree. Sean "Burton Radons" <loth@users.sourceforge.net> wrote in message news:befel6$qo1$1@digitaldaemon.com... > Sean L. Palmer wrote: > > Why would you ever want a class method to be able to change its 'this' pointer? C++ makes this const for a good reason. > > I'm not talking about "this" in class, only about struct. This is currently how it's done: > > struct vec3 > { > vec3 mulass (vec3 other) > { > return *this = *this * other; > } > } > > Pointers can be more than one cell in length, can be null, and can be re-assigned. "this" in struct is invalid on all counts: > > void foo () > { > vec3 bar; > if (this === null) /* Never true */ > this [1]; /* Invalid */ > this = &bar; /* Invalid */ > } |
July 28, 2003 Re: this * for struct methods versus inout this | ||||
---|---|---|---|---|
| ||||
Posted in reply to Burton Radons | Burton Radons <loth@users.sourceforge.net> wrote in news:befel6$qo1$1@digitaldaemon.com: > Pointers can be more than one cell in length, can be null, and can be re-assigned. "this" in struct is invalid on all counts: > > void foo () > { > vec3 bar; > if (this === null) /* Never true */ > this [1]; /* Invalid */ > this = &bar; /* Invalid */ > } > Actually, "this" can be null, especially since Walter allowed allocation of structs with new. Of course, I agree that making "this" should be an inout reference. Farmer. |
Copyright © 1999-2021 by the D Language Foundation