From af617be67a4e038354617b272d373a6fbe583644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20M=20G=C3=B3mez?= Date: Wed, 20 Sep 2023 11:02:55 +0100 Subject: [PATCH] removes references to `this` in the `constructor` section (#22730) --- doc/manual_experimental.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/manual_experimental.md b/doc/manual_experimental.md index dd28fa67c1..d05a693bb9 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.