【问题标题】:C compile error: conversion to non-scalar type requestedC 编译错误:请求转换为非标量类型
【发布时间】:2013-07-02 02:13:10
【问题描述】:

在 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

错误是什么意思,我该如何解决?

【问题讨论】:

    标签: c string syntax


    【解决方案1】:

    您确定 AddressItem_Callback_ContextType 是指针类型吗?您只能将指针类型(此处为上下文)转换为另一种指针类型。

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

    【讨论】:

      【解决方案2】:

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

      typedef struct
      {
        char *Icon;
      }AddressItem_Callback_ContextType;
      

      试试

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

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

      【讨论】:

        猜你喜欢
        • 2015-12-01
        • 2019-01-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多