Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "log"
- )
- type Point struct {
- X float64
- Y float64
- }
- // function as constructor
- func NewPoint(x float64, y float64) *Point {
- p := new(Point)
- p.X = x
- p.Y = y
- return p
- }
- func main() {
- p := NewPoint(3, 4)
- if !(p.X == 3.0) {
- log.Fatal("Wrong value")
- }
- if !(p.Y == 4.0) {
- log.Fatal("Wrong value")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement