2014-07-13 15 views
6

consideri il seguente esempio:non può convertire zero a digitare x

lock.RLock() 
    var product *Product 
    if store[productId] != nil {  //cannot convert nil to type Product 
     product = &Product{} 
     *product = *store[productId] //invalid indirect of store[productId] (type Product) 
    } 
    lock.RUnlock() 

Le eccezioni sono come commentato per linea e non ho davvero ottenere ciò che sto facendo male ..

store è un map[int]Product

qualche idea?

risposta

6

Si utilizza store come se fosse dichiarato come:

store := make(map[int]*Product) 
Problemi correlati