Custom type passed to function as a parameter

前端 未结 2 1859
悲&欢浪女
悲&欢浪女 2020-11-30 11:38

When I define a custom type, it seems that the type of the underlying type makes a difference about whether I can pass it to a function as is or I need to convert it.

2条回答
  •  死守一世寂寞
    2020-11-30 12:19

    Go has a strict type system. Just because your type is merely an alias for int doesn't mean you can interchange the two freely, you'll still have to do a type conversion. Below is a working version of your main, here's the code on play ground: https://play.golang.org/p/BDTXnnG9Lg

提交回复
热议问题