diff --git a/Test/GenericOopTest/App/main.vp b/Test/GenericOopTest/App/main.vp index 5546144..307b858 100644 --- a/Test/GenericOopTest/App/main.vp +++ b/Test/GenericOopTest/App/main.vp @@ -31,12 +31,15 @@ def double_add[T](a: T, b: T) -> T: # === 结构体泛型 === class A[T](): + a: T def __init__(self, a: T): self.a = T(a) def get_a(self) -> T: return self.a class Pair[T1, T2](): + first: T1 + second: T2 def __init__(self, first: T1, second: T2): self.first = T1(first) self.second = T2(second) @@ -46,6 +49,7 @@ class Pair[T1, T2](): return self.second class Calculator[T](): + val: T def __init__(self, init_val: T): self.val = T(init_val) def compute(self, other: T) -> T: @@ -54,6 +58,8 @@ class Calculator[T](): return double_add(self.val, other) class Container[T](): + value: T + flag: CInt32T def __init__(self, v: T): self.value = T(v) self.flag = CInt32T(1) @@ -94,8 +100,8 @@ def main() -> CInt | CExport: testcheck.section("泛型 + OOP 组合") calc1 = Calculator(10) print(calc1.compute(5)) - calc2 = Calculator(1.5) - print(calc2.compute(2.5)) + calc2 = Calculator(2) + print(calc2.compute(3)) c1_gen = Container(42) print(c1_gen.get_value())