feat: implement objects moving and borrowing
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
class Animal
|
||||
{
|
||||
str type;
|
||||
str name;
|
||||
int age;
|
||||
|
||||
fn copy() Animal
|
||||
{
|
||||
Animal cp = new Animal;
|
||||
cp.type = this.type;
|
||||
cp.name = this.name;
|
||||
cp.age = this.age;
|
||||
|
||||
return cp;
|
||||
}
|
||||
}
|
||||
|
||||
Animal a = new Animal;
|
||||
a.type = "Cow";
|
||||
a.name = "Buryatka";
|
||||
a.age = 5;
|
||||
|
||||
Animal b = a.copy();
|
||||
a.name = "Gavryusha";
|
||||
a.age = 10;
|
||||
|
||||
printline(a);
|
||||
printline(b);
|
||||
|
||||
if (a.type == b.type && a.name != b.name && a.age < b.age)
|
||||
printline("Test passed");
|
||||
else
|
||||
printline("Test failed");
|
||||
|
||||
Reference in New Issue
Block a user