-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclass.atlas
42 lines (38 loc) · 1.09 KB
/
class.atlas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//everything in this file is purely theoretical and does not work in the current version of the compiler
public trait Shape {
func getArea(&self) -> i64;
}
public class Rectangle : Shape {
private:
width: i64;
height: i64;
public:
func new(width: i64, height: i64) -> Rectangle {
return Rectangle {
width: width,
height: height
}
}
func setWidth(&self, w: i64) {
self.width = w;
}
func setHeight(&self, h: i64) {
self.height = h;
}
func getWidth(&self) -> i64 {
return self.width;
}
func getHeight(&self) -> i64 {
return self.height;
}
#[override(Shape::getArea)] //Why? Because you can implement multiple traits, and the compiler needs to know which one you are implementing
func getArea(&self) -> i64 {
return self.width * self.height;
}
}
func main() -> i64 {
let r = Rectangle::new(10, 20);
r.setWidth(30);
r.setHeight(40);
return r.getArea();
}