Updated docs to new version
This commit is contained in:
@@ -33,6 +33,29 @@ class Player
|
||||
}
|
||||
```
|
||||
|
||||
### Virtual Methods
|
||||
|
||||
The `virtual` keyword marks methods as dispatchable through the vtable, enabling polymorphic behavior:
|
||||
|
||||
```mist
|
||||
pub class Animal
|
||||
{
|
||||
str& name;
|
||||
|
||||
pub constructor(str& name)
|
||||
{
|
||||
self.name = name;
|
||||
}
|
||||
|
||||
pub virtual void speak(&self)
|
||||
{
|
||||
println!("...");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
When a method is marked `virtual`, it can be overridden in subclasses and will be dispatched dynamically at runtime through the vtable. Non-virtual methods are called statically.
|
||||
|
||||
### Inheritance
|
||||
|
||||
```mist
|
||||
@@ -59,6 +82,8 @@ void speak(&self) override(Animal)
|
||||
}
|
||||
```
|
||||
|
||||
Methods marked `override` are automatically virtual if the parent method is virtual. The semantic analyzer validates that overridden methods match the parent's signature.
|
||||
|
||||
### Implementations
|
||||
|
||||
You can implement directly on the class body:
|
||||
|
||||
Reference in New Issue
Block a user