RosettaCodeData/Task/Call-an-object-method/V-(Vlang)/call-an-object-method-1.v
2023-07-01 13:44:08 -04:00

21 lines
407 B
V

// Assigning methods to structs
struct HelloWorld {}
// Method's in Vlang are functions with special receiver arguments at the front (between fn and method name)
fn (sh HelloWorld) say_hello() {
println("Hello, world!")
}
fn (sb HelloWorld) say_bye() {
println("Goodbye, world!")
}
fn main() {
// instantiate object
hw := HelloWorld{}
// call methods of object
hw.say_hello()
hw.say_bye()
}