2016-04-26 8 views
0
package main 

import (
    "fmt" 
) 

type alias int 
type aliases []*alias 

func main() { 
    a1 := alias(1) 
    t := aliases{&a1} 

    fmt.Println([]*int([]*alias(t))) 
} 

Der Typ type aliases []*alias ist im Wesentlichen []*intWie ein Stück vom Typ Aliase Typ umwandeln

Ich tippt diese aliases wieder in die Lage sein will, konvertieren []*int

Antwort

0

Versuchen Sie, könnten Sie, indem Sie das tun richtiges Gießen.

type alias int 
type aliases []*alias 

func main() { 
    a1 := alias(1) 
    t := aliases{&a1} 

    orig := int(*([]*alias(t)[0])) 
    fmt.Println(orig) 
} 

Beispiel auf http://play.golang.org/p/1WosCIUZSa

Wenn Sie alle Werte erhalten möchten (nicht nur der erste Index), die Sie Schleife haben und jedes Element gegossen.

func main() { 
    a1 := alias(1) 
    t := aliases{&a1} 

    orig := []*int{} 

    for _, each := range t { 
     temp := int(*each) 
     orig = append(orig, &temp) 
    } 

    fmt.Printf("%#v\n", orig) // []*int{(*int)(0x10434114)} 
} 

Beispiel: http://play.golang.org/p/Sx4JK3kA45

Verwandte Themen