Skip to content

Commit 6c5b277

Browse files
committed
Update examples
1 parent e4daf1d commit 6c5b277

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/content/docs/Generic Programming/anyinterfaces.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ One of the interfaces available in the standard library is Printable, which cont
116116
If we implemented it for our struct above it might look like this:
117117

118118
```c3
119-
fn String Baz.to_new_string(Baz baz, Allocator allocator) @dynamic
119+
fn String Baz.to_new_string(Baz* baz, Allocator allocator) @dynamic
120120
{
121121
return string::printf("Baz(%d)", baz.x, allocator: allocator);
122122
}
@@ -145,10 +145,10 @@ implement the interface completely may implicitly be cast to the interface.
145145
So for example:
146146

147147
```c3
148-
Bob b = { 1 };
148+
Baz b = { 1 };
149149
double d = 0.5;
150150
int i = 3;
151-
MyName a = &b; // Valid, Bob implements MyName.
151+
MyName a = &b; // Valid, Baz implements MyName.
152152
// MyName c = &d; // Error, double does not implement MyName.
153153
MyName c = (MyName)&d; // Would break at runtime as double doesn't implement MyName
154154
// MyName z = &i; // Error, implicit conversion because int doesn't explicitly implement it.
@@ -201,14 +201,14 @@ fn void main()
201201
{
202202
int i;
203203
double d;
204-
Bob bob;
204+
Baz baz;
205205
206206
any a = &i;
207207
whoareyou2(a); // Prints "I am int!"
208208
a = &d;
209209
whoareyou2(a); // Prints "I don't know who I am."
210-
a = &bob;
211-
whoareyou2(a); // Prints "I am Bob!"
210+
a = &baz;
211+
whoareyou2(a); // Prints "I am Baz!"
212212
}
213213
```
214214

@@ -218,6 +218,21 @@ A `struct` with an "inline" member or a `typedef` which is declared with "inline
218218
inherit dynamic methods from its inline "parent". This inheritance is not
219219
available for "inline" enums.
220220

221+
```c3
222+
struct BazParent
223+
{
224+
inline Baz b;
225+
int x;
226+
}
227+
228+
fn void main()
229+
{
230+
BazParent bp;
231+
any a = &bp;
232+
whoareyou2(a); // Prints "I am Baz!"
233+
}
234+
```
235+
221236
### Reflection invocation
222237
*This functionality is not yet implemented and may see syntax changes*
223238

0 commit comments

Comments
 (0)