main
2wenty1ne 2024-11-05 12:56:25 +01:00
commit dc8a85c784
1 changed files with 44 additions and 0 deletions

44
main.zig 100644
View File

@ -0,0 +1,44 @@
const std = @import("std");
const expect = std.testing.expect;
const MeinTyp = struct {
a: f64,
b: f64,
fn init(self: *MeinTyp) void {
self.a = 1.0;
self.b = 1.0;
}
};
fn MyType(comptime T:type) type {
return struct {
const Self = @This();
a: T,
b: T,
fn init(this: *Self) void {
this.a = 1.0;
this.b = 1.0;
}
};
}
test "MeinTyp" {
var mt: MeinTyp = undefined;
mt.init();
try expect(mt.a == 1.0);
try expect(mt.b == 1.0);
}
test "MyType" {
const Myt = MyType(f64);
var myInt: Myt = undefined;
myInt.init();
try expect(myInt.a == 1.0);
try expect(myInt.b == 1.0);
myInt.a = 2.0;
myInt.b = 3.0;
try expect(myInt.a == 2.0);
try expect(myInt.b == 3.0);
}