D - this * for struct methods versus inout this
- Burton Radons (4/4) Jul 07 2003 When in a struct method, the "this" is a pointer to the struct. It'd be...
- Sean L. Palmer (5/9) Jul 08 2003 Why would you ever want a class method to be able to change its 'this'
- Burton Radons (19/21) Jul 08 2003 I'm not talking about "this" in class, only about struct. This is
- Sean L. Palmer (5/26) Jul 10 2003 You're saying it should be a reference instead of a pointer.
- Farmer (6/17) Jul 28 2003 Actually, "this" can be null, especially since Walter allowed
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.
Jul 07 2003
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.
Jul 08 2003
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 */ }
Jul 08 2003
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 */ }
Jul 10 2003
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.
Jul 28 2003