jweinst1
5/5/2016 - 6:44 AM

sample integer struct container in go

sample integer struct container in go

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
}