From 306f6f91e1597790abecf5ed0d68329b362ec6a2 Mon Sep 17 00:00:00 2001 From: Luke Date: Thu, 28 Aug 2025 18:01:04 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E5=A2=9E=E5=8A=A0=20Demo27=20=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- playground/Demo/Demo28/Main.snow | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 playground/Demo/Demo28/Main.snow diff --git a/playground/Demo/Demo28/Main.snow b/playground/Demo/Demo28/Main.snow new file mode 100644 index 0000000..255da08 --- /dev/null +++ b/playground/Demo/Demo28/Main.snow @@ -0,0 +1,33 @@ +module: Main + // Animal结构体 + struct: Animal + // 字段 + fields: + declare name: string + // 构造函数 + init: + params: + n: string + body: + this.name = n + end body + end init + + // Animal结构体封装的函数 + function: getName + returns: string + body: + // 返回字段 name + return this.name + end body + end function + + + // 程序入口 + function: main + returns: void + body: + // 实例化一个叫A的Animal,并且调用构造函数 + declare a: Animal = new Animal("GenericAnimal") + end function +end module