конкретных типов и потом этот массив заполнять объектами соответствующего типа
                  
                  
                  
                  
                  
                  делаю я это так: 
                  
                  
                  type matchedObstacle struct {
                  
                  
                    distance      float64
                  
                  
                    point         [3]float64
                  
                  
                    obstacleIndex int
                  
                  
                  }
                  
                  
                  
                  
                  
                  var matchedObstacles []struct{};
                  
                  
                  matchedObstacles = append(matchedObstacles, &matchedObstacle{distance:d, point: [3]float64{x1, y1, z1}, obstacleIndex:key});
                  
                  
                  
                  
                  
                  но получаю ошибку "cannot use matchedObstacle literal (type *matchedObstacle) as type struct {} in append"
                  
                  
                  Подскажите, как правильно выполнять такую операцию?
                  
                  
                
Я кажись понял чего у вам не так. при объявлении matchedObstacles в: var matchedObstacles []struct{}; Вы объявляете массив структур каких то. Надо объявить массив ссылок на matchedObstacle типо так: var arrayMatchedObstacle []*matchedObstacle Тогда и добовлять: arrayMatchedObstacle = append(arrayMatchedObstacle, &matchedObstacle{distance:d, point: [3]float64{x1, y1, z1}, obstacleIndex:key});
Обсуждают сегодня