Call an object method: Difference between revisions
Content added Content deleted
imported>Acediast (→{{header|COBOL}}: switched to free format) |
Recombinant (talk | contribs) m (→{{header|Zig}}: update to use Zig's testing) |
||
Line 2,345: | Line 2,345: | ||
Zig does not have classes nor objects. Zig's structs, however, can have methods; but they are not special. They are only namespaced functions that can be called with dot syntax. |
Zig does not have classes nor objects. Zig's structs, however, can have methods; but they are not special. They are only namespaced functions that can be called with dot syntax. |
||
<syntaxhighlight lang="zig">const |
<syntaxhighlight lang="zig">const testing = @import("std").testing; |
||
pub const ID = struct { |
pub const ID = struct { |
||
Line 2,375: | Line 2,375: | ||
}; |
}; |
||
// test getAge() method call |
|||
try testing.expectEqual(@as(u7, 18), person1.getAge()); |
|||
try testing.expectEqual(@as(u7, 20), ID.getAge(person2)); |
|||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
In zkl, a class can be static (there will only exist one instance of the class). A function is always a member of some class but will only be static if it does not refer to instance data. |
In zkl, a class can be static (there will only exist one instance of the class). A function is always a member of some class but will only be static if it does not refer to instance data. |