diff options
author | Juan M Gómez <info@jmgomez.me> | 2023-09-20 11:02:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-20 12:02:55 +0200 |
commit | af617be67a4e038354617b272d373a6fbe583644 (patch) | |
tree | 83b7d6423cb72915db7ee5e1992acb12e8556bbf /doc | |
parent | fefde3a735c3bc931a4d3289e43f3b95f65e1256 (diff) | |
download | Nim-af617be67a4e038354617b272d373a6fbe583644.tar.gz |
removes references to `this` in the `constructor` section (#22730)
Diffstat (limited to 'doc')
-rw-r--r-- | doc/manual_experimental.md | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/doc/manual_experimental.md b/doc/manual_experimental.md index dd28fa67c..d05a693bb 100644 --- a/doc/manual_experimental.md +++ b/doc/manual_experimental.md @@ -2341,11 +2341,10 @@ type Foo* = object x: int32 proc makeFoo(x: int32): Foo {.constructor.} = - this.x = x + result.x = x ``` It forward declares the constructor in the type definition. When the constructor has parameters, it also generates a default constructor. -Notice, inside the body of the constructor one has access to `this` which is of the type `ptr Foo`. No `result` variable is available. Like `virtual`, `constructor` also supports a syntax that allows to express C++ constraints. @@ -2371,11 +2370,11 @@ type NimClass* = object of CppClass proc makeNimClass(x: int32): NimClass {.constructor:"NimClass('1 #1) : CppClass(0, #1)".} = - this.x = x + result.x = x # Optional: define the default constructor explicitly proc makeCppClass(): NimClass {.constructor: "NimClass() : CppClass(0, 0)".} = - this.x = 1 + result.x = 1 ``` In the example above `CppClass` has a deleted default constructor. Notice how by using the constructor syntax, one can call the appropiate constructor. |