mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2024-11-28 09:09:07 +00:00
Merge branch 'master' of github.com:gopl-zh/gopl-zh.github.com
This commit is contained in:
commit
ecac9edd91
@ -72,13 +72,13 @@ Point{1, 2}.Distance(q) // Point
|
|||||||
pptr.ScaleBy(2) // *Point
|
pptr.ScaleBy(2) // *Point
|
||||||
```
|
```
|
||||||
|
|
||||||
或者接收器形参是类型T,但接收器实参是类型`*T`,这种情况下编译器会隐式地为我们取变量的地址:
|
或者接收器实参是类型T,但接收器形参是类型`*T`,这种情况下编译器会隐式地为我们取变量的地址:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
p.ScaleBy(2) // implicit (&p)
|
p.ScaleBy(2) // implicit (&p)
|
||||||
```
|
```
|
||||||
|
|
||||||
或者接收器形参是类型`*T`,实参是类型T。编译器会隐式地为我们解引用,取到指针指向的实际变量:
|
或者接收器实参是类型`*T`,形参是类型T。编译器会隐式地为我们解引用,取到指针指向的实际变量:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
pptr.Distance(q) // implicit (*pptr)
|
pptr.Distance(q) // implicit (*pptr)
|
||||||
|
Loading…
Reference in New Issue
Block a user