2013-07-04 40 views
1

在C中,我嘗試分配一個字符串:Ç編譯錯誤:轉換到非標量型要求

void addressItem_icon_download_callback(const char* res_name, 
             int success, 
             void *context, 
             char *last_modified){ 

    char *icon = ((AddressItem_Callback_ContextType)context)->Icon; 
} 

,並得到這個錯誤:

conversion to non-scalar type requested 

什麼是錯誤的含義及如何我能解決這個問題嗎?

回答

3

假設AddressItem_Callback_ContextType是與現場圖標結構(char*

typedef struct 
{ 
    char *Icon; 
}AddressItem_Callback_ContextType; 

嘗試

char *icon = ((AddressItem_Callback_ContextType*)context)->Icon; 

首先,你必須投你的背景爲指針AddressItem_Callback_ContextType* 和那麼只有你可以訪問該字段使用「 - >」

0

您確定AddressItem_Callback_ContextType是apointer類型嗎?你只能將一個指針類型(這裏是上下文)轉換爲另一個指針類型。

可能需要將上下文轉換爲(AddressItem_Callback_ContextType *)。

相關問題