If you imagine I have the following declarations:
type Car struct {
Vehicle
engineType string
}
type Bus struct {
Vehicle
public bool
engineType string
}
type Bike struct {
Vehicle
motorbike bool
}
type Vehicle struct {
NumberWheels int
NumberPassengers int
Owner string
}
type Vehicles []Vehicle
I'm trying to have an array of Vehicles. However this is not possible as they each have a different type ( i.e Car, Bus, Bike, etc...)
var myCar = Car{Vehicle{4, 4, "Me"}, "Manual"}
var myBike = Bike{Vehicle{2, 0, "Bob and I"}, false}
var myVehicles = Vehicles{myCar, myBike}
for i := range myVehicles {
fmt.Println(myVehicles[i])
}
How would you achieve something like this. Or am I trying to tackle this problem from the wrong angle. I'm new to Go.