Tin

Examples · learn/11-values · 173 of 339

inout-method

examples/learn/11-values/inout-method.tintin run examples/learn/11-values/inout-method.tin
type Counter = { count: int }

// A method whose first parameter is inout changes the value it is called on.
fn Counter.bump(c: inout Counter) {
  c.count += 1
}

fn main() {
  var clicks = Counter { count: 0 }
  clicks.bump()             // a method call on a var needs no &
  clicks.bump()
  print(clicks.count)
}