2 ms·
When I say "type MyInt int" didn't I just type-alias int? No, you created a new type. cmccabe@keter:~/tmp> cat inta.go package main import "fmt" type
by colin_mccabe 12y ago
When I say "type MyInt int" didn't I just type-alias int?
No, you created a new type.
cmccabe@keter:~/tmp> cat inta.go
package main
import "fmt"
type myfoo int
func printint(i int) {
fmt.Printf("i = %d\n", i)
}
func main() {
var foo myfoo
printint(foo)
}
cmccabe@keter:~/tmp> go build inta.go
# command-line-arguments
./inta.go:13: cannot use foo (type myfoo) as type int in argument to printint
You are probably thinking about "typedef" in C++, but go works differently in this case.