September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,30 @@
struct MyClass {
variable: i32, // member variable = instance variable
}
impl MyClass {
// member function = method, with its implementation
fn some_method(&mut self) {
self.variable = 1;
}
// constructor, with its implementation
fn new() -> MyClass {
// Here could be more code.
MyClass { variable: 0 }
}
}
fn main () {
// Create an instance in the stack.
let mut instance = MyClass::new();
// Create an instance in the heap.
let mut p_instance = Box::<_>::new(MyClass::new());
// Invoke method on both istances,
instance.some_method();
p_instance.some_method();
// Both instances are automatically deleted when their scope ends.
}