gpt4 book ai didi

c - 在c中初始化一个新结构

转载 作者:太空宇宙 更新时间:2023-11-04 00:38:50 26 4
gpt4 key购买 nike

我试图在 c 中初始化一个新的结构。

我的语法有什么问题?

    AddressItem_Callback_ContextType *context;

//check if icons need to be downloaded
if (pEntity->cBigIcon[0] != 0){
if (res_get(RES_BITMAP,RES_SKIN, pEntity->cBigIcon) == NULL){

context = {pEntity->iID, pEntity->cBigIcon};
//context->Icon = pEntity->cBigIcon;
//context->iID = pEntity->iID;

res_download(RES_DOWNLOAD_IMAGE, pEntity->cBigIcon, NULL, "",TRUE, 1, addressItem_icon_download_callback, context );
}
}

我也收到语法错误:

    AddressItem_Callback_ContextType *context = {0,NULL};

//check if icons need to be downloaded
if (pEntity->cBigIcon[0] != 0){
if (res_get(RES_BITMAP,RES_SKIN, pEntity->cBigIcon) == NULL){

//context = {pEntity->iID, pEntity->cBigIcon};
context->Icon = pEntity->cBigIcon;
context->iID = pEntity->iID;

res_download(RES_DOWNLOAD_IMAGE, pEntity->cBigIcon, NULL, "",TRUE, 1, addressItem_icon_download_callback, context );
}
}

if (pEntity->cSmallIcon[0] != 0){
if (res_get(RES_BITMAP,RES_SKIN, pEntity->cSmallIcon) == NULL){

//context = {pEntity->iID, pEntity->cSmallIcon};
context->Icon = pEntity->cSmallIcon;
context->iID = pEntity->iID;

res_download(RES_DOWNLOAD_IMAGE, pEntity->cSmallIcon, NULL, "",TRUE, 1, addressItem_icon_download_callback, context );
}
}

那么这个 (3) 应该行得通吗?

 AddressItem_Callback_ContextType context = {0,NULL};

//check if icons need to be downloaded
if (pEntity->cBigIcon[0] != 0){
if (res_get(RES_BITMAP,RES_SKIN, pEntity->cBigIcon) == NULL){

//context = {pEntity->iID, pEntity->cBigIcon};
context.Icon = pEntity->cBigIcon;
context.iID = pEntity->iID;

res_download(RES_DOWNLOAD_IMAGE, pEntity->cBigIcon, NULL, "",TRUE, 1, addressItem_icon_download_callback, context );
}
}

if (pEntity->cSmallIcon[0] != 0){
if (res_get(RES_BITMAP,RES_SKIN, pEntity->cSmallIcon) == NULL){

//context = {pEntity->iID, pEntity->cSmallIcon};
context.Icon = pEntity->cSmallIcon;
context.iID = pEntity->iID;

res_download(RES_DOWNLOAD_IMAGE, pEntity->cSmallIcon, NULL, "",TRUE, 1, addressItem_icon_download_callback, context );
}
}

最佳答案

context = {pEntity->iID, pEntity->cBigIcon};

{} 初始化列表只能在声明时使用,不能在赋值表达式中使用。

您必须将其分解为两个赋值语句(为此您还必须初始化未初始化的 context 指针)。

关于c - 在c中初始化一个新结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17451200/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com