digitalmars.D - How do I refer to /this/ object?
- Nils Hensel (4/4) Apr 23 2005 Hello everybody,
- Unknown W. Brackets (2/8) Apr 23 2005
- Andrew Fedoniouk (4/4) Apr 23 2005 According to http://www.digitalmars.com/d/lex.html#keyword :)
- Derek Parnell (30/35) Apr 23 2005 The answer is 'this'.
- Nils Hensel (16/17) Apr 23 2005 Thanks to all for your answers. Actually I tried this but always got a
- TechnoZeus (3/19) Apr 24 2005 It is inhereted, but under the name "super" rather than "this" so that y...
Hello everybody, what is D's equivalent to C++'s "this" keyword? How can I refer to the object instance itself? Nils
Apr 23 2005
Umm... this? How does the D "this" differ from the C++ "this"? -[Unknown]Hello everybody, what is D's equivalent to C++'s "this" keyword? How can I refer to the object instance itself? Nils
Apr 23 2005
According to http://www.digitalmars.com/d/lex.html#keyword :) D has also 'this' keyword. this.param = 123; Andrew.
Apr 23 2005
On Sun, 24 Apr 2005 00:24:30 +0200, Nils Hensel wrote:Hello everybody, what is D's equivalent to C++'s "this" keyword? How can I refer to the object instance itself?The answer is 'this'. Example code: //---------------- import std.stdio; class Foo { char[] v; this() { v = "abc".dup; } void disp(char[] v) { writefln("%s", this.v ~ v); } } void main() { Foo f = new Foo; f.disp("def"); } //------------ -- Derek Parnell Melbourne, Australia 24/04/2005 9:05:35 AM
Apr 23 2005
Derek Parnell schrieb:The answer is 'this'.Thanks to all for your answers. Actually I tried this but always got a compiler error which I thought was connected to "this". What actually got me was: <D Documentation> If there is no constructor for a class, but there is a constructor for the base class, a default constructor of the form: this() { } is implicitly generated. </D Documentation> Somehow I was thinking that the constructor would be inherited. I'm too tired for programming right now I believe. Too many stupid ideas. Better get some sleep. ;-) Thanks anyway, Nils
Apr 23 2005
"Nils Hensel" <nils.hensel web.de> wrote in message news:d4emra$2ksa$1 digitaldaemon.com...Derek Parnell schrieb:It is inhereted, but under the name "super" rather than "this" so that you have access to both. TZThe answer is 'this'.Thanks to all for your answers. Actually I tried this but always got a compiler error which I thought was connected to "this". What actually got me was: <D Documentation> If there is no constructor for a class, but there is a constructor for the base class, a default constructor of the form: this() { } is implicitly generated. </D Documentation> Somehow I was thinking that the constructor would be inherited. I'm too tired for programming right now I believe. Too many stupid ideas. Better get some sleep. ;-) Thanks anyway, Nils
Apr 24 2005