Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- //go program to implement a portable VM
- import (
- "fmt"
- )
- //int object struct
- type Int struct {
- value []int
- }
- //constructor for int struct
- func CreateInt(val int) Int {
- num := Int{value:[]int{val}}
- return num
- }
- //adds an integer to the struct
- func (in Int) Addto(amount int) {
- in.value[0] += amount
- }
- func main(){
- tester := CreateInt(8)
- tester.Addto(7)
- fmt.Println(tester)
- //{[15]}
- fmt.Println(len(tester.value))
- //1
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement