digitalmars.D.learn - is there "this"?
- Konstantin Kutsevalov (14/14) Nov 01 2016 The question is simple.
- rikki cattermole (3/17) Nov 01 2016 You forgot an int in the arguments but otherwise that would work fine
- Konstantin Kutsevalov (4/28) Nov 01 2016 yes I missed "int", but it's just an example.
- Konstantin Kutsevalov (7/36) Nov 01 2016 I tested already and it really works, thank you.
- Bauss (4/21) Nov 02 2016 Well "this" in D has different meanings as it depends on its
- Jonathan M Davis via Digitalmars-d-learn (5/7) Nov 02 2016 Yes, but it's almost always the same thing that you'd expect from a lang...
- Jonathan M Davis via Digitalmars-d-learn (7/12) Nov 02 2016 I don't know why you were having trouble before, but I think that most
- Steven Schveighoffer (8/19) Nov 03 2016 In the case of the original post, however, you *need* to use this.value,...
- Jonathan M Davis via Digitalmars-d-learn (4/25) Nov 03 2016 Yeah. That's the only reason that I ever use the this pointer/reference.
- Konstantin Kutsevalov (5/13) Nov 04 2016 I'd like to use "this" because when I see something like
The question is simple. Is there something like "this" word for classes? For example: ``` class CLS { int numberValue; public this(numberValue) { // how can I put the local numberValue to class property? // in some prog language I can do like: // this.numberValue = numberValue; } } ```
Nov 01 2016
On 02/11/2016 3:17 PM, Konstantin Kutsevalov wrote:The question is simple. Is there something like "this" word for classes? For example: ``` class CLS { int numberValue; public this(numberValue) { // how can I put the local numberValue to class property? // in some prog language I can do like: // this.numberValue = numberValue; } } ```You forgot an int in the arguments but otherwise that would work fine with your line uncommented.
Nov 01 2016
On Wednesday, 2 November 2016 at 02:20:43 UTC, rikki cattermole wrote:On 02/11/2016 3:17 PM, Konstantin Kutsevalov wrote:yes I missed "int", but it's just an example. so if I'll write "this.property = value" it will work?The question is simple. Is there something like "this" word for classes? For example: ``` class CLS { int numberValue; public this(numberValue) { // how can I put the local numberValue to class property? // in some prog language I can do like: // this.numberValue = numberValue; } } ```You forgot an int in the arguments but otherwise that would work fine with your line uncommented.
Nov 01 2016
On Wednesday, 2 November 2016 at 02:33:10 UTC, Konstantin Kutsevalov wrote:On Wednesday, 2 November 2016 at 02:20:43 UTC, rikki cattermole wrote:I tested already and it really works, thank you. I asked that because I tried once to use "this" in past but I got error. So I asked on some forum "how to get property of class?" and peoples said that I may use just a name of property. So I thought that there isn't "this" word.On 02/11/2016 3:17 PM, Konstantin Kutsevalov wrote:yes I missed "int", but it's just an example. so if I'll write "this.property = value" it will work?The question is simple. Is there something like "this" word for classes? For example: ``` class CLS { int numberValue; public this(numberValue) { // how can I put the local numberValue to class property? // in some prog language I can do like: // this.numberValue = numberValue; } } ```You forgot an int in the arguments but otherwise that would work fine with your line uncommented.
Nov 01 2016
On Wednesday, 2 November 2016 at 02:42:01 UTC, Konstantin Kutsevalov wrote:On Wednesday, 2 November 2016 at 02:33:10 UTC, Konstantin Kutsevalov wrote:Well "this" in D has different meanings as it depends on its context sometimes.On Wednesday, 2 November 2016 at 02:20:43 UTC, rikki cattermole wrote:I tested already and it really works, thank you. I asked that because I tried once to use "this" in past but I got error. So I asked on some forum "how to get property of class?" and peoples said that I may use just a name of property. So I thought that there isn't "this" word.On 02/11/2016 3:17 PM, Konstantin Kutsevalov wrote:yes I missed "int", but it's just an example. so if I'll write "this.property = value" it will work?[...]You forgot an int in the arguments but otherwise that would work fine with your line uncommented.
Nov 02 2016
On Wednesday, November 02, 2016 07:26:57 Bauss via Digitalmars-d-learn wrote:Well "this" in D has different meanings as it depends on its context sometimes.Yes, but it's almost always the same thing that you'd expect from a language like C++ or Java. - Jonathan M Davis
Nov 02 2016
On Wednesday, November 02, 2016 02:42:01 Konstantin Kutsevalov via Digitalmars-d-learn wrote:I tested already and it really works, thank you. I asked that because I tried once to use "this" in past but I got error. So I asked on some forum "how to get property of class?" and peoples said that I may use just a name of property. So I thought that there isn't "this" word.I don't know why you were having trouble before, but I think that most people never use an explicit this unless they need to, so plenty of folks would have just told you to remove the this from you code, especially if it worked without. - Jonathan M Davis
Nov 02 2016
On 11/2/16 4:43 AM, Jonathan M Davis via Digitalmars-d-learn wrote:On Wednesday, November 02, 2016 02:42:01 Konstantin Kutsevalov via Digitalmars-d-learn wrote:In the case of the original post, however, you *need* to use this.value, as the parameter masks the member of the same name. Using 'this' removes ambiguity. This is a typical pattern seen in many languages. Often the intuitive name of a member is the same name as you want for the parameter of the constructor. -SteveI tested already and it really works, thank you. I asked that because I tried once to use "this" in past but I got error. So I asked on some forum "how to get property of class?" and peoples said that I may use just a name of property. So I thought that there isn't "this" word.I don't know why you were having trouble before, but I think that most people never use an explicit this unless they need to, so plenty of folks would have just told you to remove the this from you code, especially if it worked without.
Nov 03 2016
On Thursday, November 03, 2016 09:40:11 Steven Schveighoffer via Digitalmars-d-learn wrote:On 11/2/16 4:43 AM, Jonathan M Davis via Digitalmars-d-learn wrote:Yeah. That's the only reason that I ever use the this pointer/reference. - Jonathan M DavisOn Wednesday, November 02, 2016 02:42:01 Konstantin Kutsevalov via Digitalmars-d-learn wrote:In the case of the original post, however, you *need* to use this.value, as the parameter masks the member of the same name. Using 'this' removes ambiguity. This is a typical pattern seen in many languages. Often the intuitive name of a member is the same name as you want for the parameter of the constructor.I tested already and it really works, thank you. I asked that because I tried once to use "this" in past but I got error. So I asked on some forum "how to get property of class?" and peoples said that I may use just a name of property. So I thought that there isn't "this" word.I don't know why you were having trouble before, but I think that most people never use an explicit this unless they need to, so plenty of folks would have just told you to remove the this from you code, especially if it worked without.
Nov 03 2016
On Thursday, 3 November 2016 at 13:40:11 UTC, Steven Schveighoffer wrote:On 11/2/16 4:43 AM, Jonathan M Davis via Digitalmars-d-learn In the case of the original post, however, you *need* to use this.value, as the parameter masks the member of the same name. Using 'this' removes ambiguity. This is a typical pattern seen in many languages. Often the intuitive name of a member is the same name as you want for the parameter of the constructor. -SteveI'd like to use "this" because when I see something like "this.pumpurum = 10;" then I understand that "pumpurum" is property of class and not some local variable :)
Nov 04 2016