繁体   English   中英

C编译错误:转换为请求的非标量类型

[英]C compile error: conversion to non-scalar type requested

在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

错误意味着什么,我该如何解决?

假设AddressItem_Callback_ContextType是一个带有字段Icon( char* )的结构

typedef struct
{
  char *Icon;
}AddressItem_Callback_ContextType;

尝试

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

首先,您必须将您的上下文转换为指针AddressItem_Callback_ContextType* ,然后只有您可以使用“ - >”访问该字段

你确定AddressItem_Callback_ContextType是apointer类型吗? 您可以将指针类型(此处为上下文)强制转换为另一种指针类型。

可能是您需要将上下文转换为(AddressItem_Callback_ContextType *)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM