-
-
Notifications
You must be signed in to change notification settings - Fork 9
Classes
Classes are structures which can have virtual methods defined on them.
import basics
class Shape () {
constructor {}
virtual func getArea() float = 0.0
}
class Rectangle extends Shape (w, h float) {
constructor(w, h float){
this.w = w
this.h = h
}
override func getArea() float = this.w * this.h
}
func main {
shape *Shape = new Rectangle(5.0f, 10.0f)
defer delete shape
print(shape.getArea())
}
All classes require a constructor and instances of classes must be constructed in order to use dynamic dispatch / virtual methods!
Classes also come with a __vtable__
field, which is implicitly initialized in class constructors. The layout of each vtable is not consistent and is only intended for use by the compiler. The only real purpose the programmer can use this value for is to determine if two values use the same vtable.
This issue was fixed in v2.8 with the introduction of super()
which you can use to call parent constructors.
Unfortunately, in Adept v2.7 (when constructors were introduced), calling parent constructors was not properly implemented!
Even if you know what you are doing, a work-around is not possible without -Onothing
, as the LLVM 14 optimizer will accidentally perform incorrect optimizations!
So if you are still using v2.7, please use regular methods if you wish to share code between constructors of different classes.