|
@@ -238,9 +238,9 @@ func main() {
|
|
|
我们知道方法将指针作为接收者不是必须的,如下面的例子,我们只是需要 `Point3` 的值来做计算:
|
|
我们知道方法将指针作为接收者不是必须的,如下面的例子,我们只是需要 `Point3` 的值来做计算:
|
|
|
|
|
|
|
|
```go
|
|
```go
|
|
|
-type Point3 struct { x, y, z float }
|
|
|
|
|
|
|
+type Point3 struct { x, y, z float64 }
|
|
|
// A method on Point3
|
|
// A method on Point3
|
|
|
-func (p Point3) Abs float {
|
|
|
|
|
|
|
+func (p Point3) Abs() float64 {
|
|
|
return math.Sqrt(p.x*p.x + p.y*p.y + p.z*p.z)
|
|
return math.Sqrt(p.x*p.x + p.y*p.y + p.z*p.z)
|
|
|
}
|
|
}
|
|
|
```
|
|
```
|